import { AggregateRoot, PostalAddress, TINNumber, UniqueID } from "@/core/common/domain";
import { Result } from "@repo/rdx-utils";

export interface ICustomerProps {
  name: string;
  tin: TINNumber;
  address: PostalAddress;
}

export interface ICustomer {
  id: UniqueID;

  name: string;
  tin: TINNumber;
  address: PostalAddress;
}

export class Customer extends AggregateRoot<ICustomerProps> implements ICustomer {
  id: UniqueID;
  static create(props: ICustomerProps, id?: UniqueID): Result<Customer, Error> {
    const customer = new Customer(props, id);

    // Reglas de negocio / validaciones
    // ...
    // ...

    // 🔹 Disparar evento de dominio "CustomerAuthenticatedEvent"
    //const { customer } = props;
    //user.addDomainEvent(new CustomerAuthenticatedEvent(id, customer.toString()));

    return Result.ok(customer);
  }

  get name() {
    return this.props.name;
  }

  get tin(): TINNumber {
    return this.props.tin;
  }

  get address(): PostalAddress {
    return this.props.address;
  }
}
