import { ValueObject } from "@repo/rdx-ddd";
import { Result } from "@repo/rdx-utils";

interface ICustomerInvoiceAddressTypeProps {
  value: string;
}

export enum INVOICE_ADDRESS_TYPE {
  SHIPPING = "shipping",
  BILLING = "billing",
}

export class CustomerInvoiceAddressType extends ValueObject<ICustomerInvoiceAddressTypeProps> {
  private static readonly ALLOWED_TYPES = ["shipping", "billing"];

  static create(value: string): Result<CustomerInvoiceAddressType, Error> {
    if (!CustomerInvoiceAddressType.ALLOWED_TYPES.includes(value)) {
      return Result.fail(
        new Error(
          `Invalid address type: ${value}. Allowed types are: ${CustomerInvoiceAddressType.ALLOWED_TYPES.join(", ")}`
        )
      );
    }
    return Result.ok(new CustomerInvoiceAddressType({ value }));
  }

  getProps(): string {
    return this.props.value;
  }

  toString() {
    return String(this.props.value);
  }

  toPrimitive(): string {
    return this.getProps();
  }
}
