import { IAuthUser } from "@/contexts/auth/domain";
import { IAuthContext } from "@/contexts/auth/infrastructure";
import { ILogin_Response_DTO } from "@shared/contexts";

export interface ILoginUser {
  user: IAuthUser;
  token: string;
  refreshToken: string;
}

export interface ILoginPresenter {
  map: (user: ILoginUser, context: IAuthContext) => ILogin_Response_DTO;
}

export const loginPresenter: ILoginPresenter = {
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  map: (loginUser: ILoginUser, context: IAuthContext): ILogin_Response_DTO => {
    const { user, token, refreshToken } = loginUser;
    const roles = user.getRoles()?.map((rol) => rol.toString()) || [];

    return {
      id: user.id.toString(),
      name: user.name.toString(),
      email: user.email.toString(),
      lang_code: user.language.toString(),
      roles,
      token,
      refresh_token: refreshToken,
    };
  },
};
