import { CurrencyCode, DomainEntity, LanguageCode, UniqueID } from "@repo/rdx-ddd"; import { Maybe, Result } from "@repo/rdx-utils"; import { CustomerInvoiceItemDescription, CustomerInvoiceItemDiscount, CustomerInvoiceItemQuantity, CustomerInvoiceItemSubtotalPrice, CustomerInvoiceItemTotalPrice, CustomerInvoiceItemUnitPrice, } from "../../value-objects"; export interface CustomerInvoiceItemProps { description: Maybe; quantity: Maybe; // Cantidad de unidades unitPrice: Maybe; // Precio unitario en la moneda de la factura discount: Maybe; // % descuento languageCode: LanguageCode; currencyCode: CurrencyCode; } export class CustomerInvoiceItem extends DomainEntity { private _subtotalPrice!: CustomerInvoiceItemSubtotalPrice; private _totalPrice!: CustomerInvoiceItemTotalPrice; public static create( props: CustomerInvoiceItemProps, id?: UniqueID ): Result { const item = new CustomerInvoiceItem(props, id); // Reglas de negocio / validaciones // ... // ... // 🔹 Disparar evento de dominio "CustomerInvoiceItemCreatedEvent" //const { customerInvoice } = props; //user.addDomainEvent(new CustomerInvoiceAuthenticatedEvent(id, customerInvoice.toString())); return Result.ok(item); } get description(): Maybe { return this.props.description; } get quantity(): Maybe { return this.props.quantity; } get unitPrice(): Maybe { return this.props.unitPrice; } get subtotalPrice(): CustomerInvoiceItemSubtotalPrice { if (!this._subtotalPrice) { this._subtotalPrice = this.calculateSubtotal(); } return this._subtotalPrice; } get discount(): Maybe { return this.props.discount; } get totalPrice(): CustomerInvoiceItemTotalPrice { if (!this._totalPrice) { this._totalPrice = this.calculateTotal(); } return this._totalPrice; } public get languageCode(): LanguageCode { return this.props.languageCode; } public get currencyCode(): CurrencyCode { return this.props.currencyCode; } getValue(): CustomerInvoiceItemProps { return this.props; } toPrimitive() { return this.getValue(); } calculateSubtotal(): CustomerInvoiceItemSubtotalPrice { throw new Error("Not implemented"); /*const unitPrice = this.unitPrice.isSome() ? this.unitPrice.unwrap() : CustomerInvoiceItemUnitPrice.zero(); return this.unitPrice.multiply(this.quantity.toNumber()); // Precio unitario * Cantidad*/ } calculateTotal(): CustomerInvoiceItemTotalPrice { throw new Error("Not implemented"); //return this.subtotalPrice.subtract(this.subtotalPrice.percentage(this.discount.toNumber())); } }