import { AuthUser } from "@/contexts/auth/domain";
import { Profile } from "@/contexts/profile/domain";
import { IProfileContext } from "@/contexts/profile/infrastructure/Profile.context";
import { IGetProfileResponse_DTO } from "@shared/contexts";

export interface IGetProfilePresenter {
  map: (
    profile: Profile,
    user: AuthUser,
    context: IProfileContext
  ) => Promise<IGetProfileResponse_DTO>;
}

export const GetProfilePresenter: IGetProfilePresenter = {
  map: async (
    profile: Profile,
    user: AuthUser,
    context: IProfileContext
  ): Promise<IGetProfileResponse_DTO> => {
    return {
      id: user.id.toString(),
      name: user.name.toString(),
      email: user.email.toString(),
      lang_code: user.language.code,
      roles: user.getRolesArray(),
      dealer: {
        id: profile.id.toString(),
        name: profile.name.toString(),
        status: profile.status.toString(),
        lang_code: profile.language.toString(),
        currency_code: profile.currency.toString(),

        contact_information: profile.contactInformation.toString(),
        default_payment_method: profile.defaultPaymentMethod.toString(),
        default_notes: profile.defaultNotes.toString(),
        default_legal_terms: profile.defaultLegalTerms.toString(),
        default_quote_validity: profile.defaultQuoteValidity.toString(),
        default_tax: profile.defaultTax.convertScale(2).toObject(),

        logo: await profile.logo.toBase64(),
      },
    };
  },
};
