import { AggregateRoot, EmailAddress, PhoneNumber, PostalAddress, TINNumber, UniqueID, } from "@repo/rdx-ddd"; import { Maybe, Result } from "@repo/rdx-utils"; export interface CustomerProps { companyId: UniqueID; reference: string; isCompany: 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; } export interface ICustomer { id: UniqueID; companyId: UniqueID; reference: string; name: string; tin: TINNumber; address: PostalAddress; email: EmailAddress; phone: PhoneNumber; legalRecord: string; defaultTax: number; langCode: string; currencyCode: string; tradeName: Maybe; fax: Maybe; website: Maybe; isIndividual: boolean; isCompany: boolean; isActive: boolean; } export class Customer extends AggregateRoot implements ICustomer { static create(props: CustomerProps, id?: UniqueID): Result { const contact = new Customer(props, id); // Reglas de negocio / validaciones // ... // ... // 🔹 Disparar evento de dominio "CustomerAuthenticatedEvent" //const { contact } = props; //user.addDomainEvent(new CustomerAuthenticatedEvent(id, contact.toString())); return Result.ok(contact); } update(partial: Partial>): Result { const updatedCustomer = new Customer({ ...this.props, ...partial }, this.id); return Result.ok(updatedCustomer); } get companyId(): UniqueID { return this.props.companyId; } get reference() { return this.props.reference; } 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 isIndividual(): boolean { return !this.props.isCompany; } get isCompany(): boolean { return this.props.isCompany; } get isActive(): boolean { return this.props.status === "active"; } }