import { Account } from "@/contexts/accounts/domain";
import { ensureBoolean, ensureNumber, ensureString } from "@repo/rdx-utils";
import { IGetAccountResponseDTO } from "../../dto";

export interface IGetAccountPresenter {
  toDTO: (account: Account) => IGetAccountResponseDTO;
}

export const getAccountPresenter: IGetAccountPresenter = {
  toDTO: (account: Account): IGetAccountResponseDTO => ({
    id: ensureString(account.id.toPrimitive()),

    is_companyr: ensureBoolean(account.isFreelancer),
    name: ensureString(account.name),
    trade_name: ensureString(account.tradeName.getOrUndefined()),
    tin: ensureString(account.tin.toPrimitive()),

    street: ensureString(account.address.street),
    city: ensureString(account.address.city),
    state: ensureString(account.address.state),
    postal_code: ensureString(account.address.postalCode),
    country: ensureString(account.address.country),

    email: ensureString(account.email.toPrimitive()),
    phone: ensureString(account.phone.toPrimitive()),
    fax: ensureString(account.fax.getOrUndefined()?.toPrimitive()),
    website: ensureString(account.website.getOrUndefined()),

    legal_record: ensureString(account.legalRecord),

    default_tax: ensureNumber(account.defaultTax),
    status: ensureString(account.isActive ? "active" : "inactive"),
    language_code: ensureString(account.langCode),
    currency_code: ensureString(account.currencyCode),
    logo: ensureString(account.logo.getOrUndefined()),
  }),
};
