import { CurrencyCode, DomainEntity, LanguageCode, MoneyValue, Percentage, UniqueID, } from "@repo/rdx-ddd"; import { Maybe, Result } from "@repo/rdx-utils"; import { CustomerInvoiceItemDescription, CustomerInvoiceItemDiscount, CustomerInvoiceItemQuantity, CustomerInvoiceItemSubtotalAmount, CustomerInvoiceItemTotalAmount, CustomerInvoiceItemUnitAmount, } from "../../value-objects"; export interface CustomerInvoiceItemProps { description: Maybe; quantity: Maybe; // Cantidad de unidades unitAmount: Maybe; // Precio unitario en la moneda de la factura discountPercentage: Maybe; // % descuento languageCode: LanguageCode; currencyCode: CurrencyCode; } export class CustomerInvoiceItem extends DomainEntity { private _subtotalAmount!: CustomerInvoiceItemSubtotalAmount; private _totalAmount!: CustomerInvoiceItemTotalAmount; 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 unitAmount(): Maybe { return this.props.unitAmount; } get subtotalAmount(): CustomerInvoiceItemSubtotalAmount { if (!this._subtotalAmount) { this._subtotalAmount = this.calculateSubtotal(); } return this._subtotalAmount; } get discountPercentage(): Maybe { return this.props.discountPercentage; } get discountAmount(): Maybe { throw new Error("Not implemented"); } get totalAmount(): CustomerInvoiceItemTotalAmount { if (!this._totalAmount) { this._totalAmount = this.calculateTotal(); } return this._totalAmount; } 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(): CustomerInvoiceItemSubtotalAmount { 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(): CustomerInvoiceItemTotalAmount { throw new Error("Not implemented"); //return this.subtotalPrice.subtract(this.subtotalPrice.percentage(this.discount.toNumber())); } }