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

interface ICustomerAddressTypeProps {
  value: string;
}

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

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

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

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

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

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