import { AggregateRoot, EmailAddress, PhoneNumber, PostalAddress, TINNumber, UniqueID, } from "@repo/rdx-ddd"; import { Result } from "@repo/rdx-utils"; import { CustomerStatus } from "../value-objects"; export interface CustomerProps { companyId: UniqueID; status: CustomerStatus; reference: string; isCompany: boolean; name: string; tradeName: string; tin: TINNumber; address: PostalAddress; email: EmailAddress; phone: PhoneNumber; fax: PhoneNumber; website: string; legalRecord: string; defaultTax: string[]; langCode: string; currencyCode: string; } export interface ICustomer { id: UniqueID; companyId: UniqueID; reference: string; tin: TINNumber; name: string; tradeName: string; address: PostalAddress; email: EmailAddress; phone: PhoneNumber; fax: PhoneNumber; website: string; legalRecord: string; defaultTax: string[]; langCode: string; currencyCode: string; 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(): PhoneNumber { return this.props.fax; } get website(): string { 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.isActive(); } }