import { AggregateRoot, EmailAddress, PhoneNumber, PostalAddress, TINNumber, UniqueID, } from "@common/domain"; import { Maybe, Result } from "@common/helpers"; export interface IAccountProps { isFreelancer: boolean; name: string; tin: TINNumber; address: PostalAddress; email: EmailAddress; phone: PhoneNumber; legalRecord: string; defaultTax: number; status: string; langCode: string; currencyCode: string; tradeName: Maybe; website: Maybe; fax: Maybe; logo: Maybe; } export interface IAccount { id: UniqueID; name: string; tin: TINNumber; address: PostalAddress; email: EmailAddress; phone: PhoneNumber; legalRecord: string; defaultTax: number; langCode: string; currencyCode: string; tradeName: Maybe; fax: Maybe; website: Maybe; logo: Maybe; isAccount: boolean; isFreelancer: boolean; isActive: boolean; } export class Account extends AggregateRoot implements IAccount { static create(props: IAccountProps, id?: UniqueID): Result { const account = new Account(props, id); // Reglas de negocio / validaciones // ... // ... // 🔹 Disparar evento de dominio "AccountAuthenticatedEvent" //const { account } = props; //user.addDomainEvent(new AccountAuthenticatedEvent(id, account.toString())); return Result.ok(account); } get name() { return this.props.name; } get tradeName() { return this.props.tradeName; } get tin(): TINNumber { return this.props.tin; } get address(): PostalAddress { return this.props.address; } get email(): EmailAddress { return this.props.email; } get phone(): PhoneNumber { return this.props.phone; } get fax(): Maybe { return this.props.fax; } get website() { return this.props.website; } get legalRecord() { return this.props.legalRecord; } get defaultTax() { return this.props.defaultTax; } get langCode() { return this.props.langCode; } get currencyCode() { return this.props.currencyCode; } get logo() { return this.props.logo; } get isAccount(): boolean { return !this.props.isFreelancer; } get isFreelancer(): boolean { return this.props.isFreelancer; } get isActive(): boolean { return this.props.status === "active"; } }