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