import { ValueObject } from "core/common/domain";
import { Result } from "core/common/helpers";

interface IInvoiceAddressTypeProps {
  value: string;
}

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

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

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

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

  toString(): string {
    return this.getValue();
  }

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