export enum CheckoutStateEnum {
  READY = 'READY',
  INSUFFICIENT_FUNDS = 'INSUFFICIENT_FUNDS',
  UNKNOWN = 'UNKNOWN'
}

export class CheckoutState {
  private constructor(private readonly state: CheckoutStateEnum) {}

  static ready(): CheckoutState {
    return new CheckoutState(CheckoutStateEnum.READY);
  }

  static insufficientFunds(): CheckoutState {
    return new CheckoutState(CheckoutStateEnum.INSUFFICIENT_FUNDS);
  }

  static unknown(): CheckoutState {
    return new CheckoutState(CheckoutStateEnum.UNKNOWN);
  }

  static fromButtonClasses(classes: string): CheckoutState {
    const normalized = classes.toLowerCase().trim();

    if (normalized.includes('btn-success')) {
      return CheckoutState.ready();
    }

    if (normalized.includes('btn')) {
      return CheckoutState.insufficientFunds();
    }

    return CheckoutState.unknown();
  }

  isReady(): boolean {
    return this.state === CheckoutStateEnum.READY;
  }

  hasInsufficientFunds(): boolean {
    return this.state === CheckoutStateEnum.INSUFFICIENT_FUNDS;
  }

  isUnknown(): boolean {
    return this.state === CheckoutStateEnum.UNKNOWN;
  }

  getValue(): CheckoutStateEnum {
    return this.state;
  }
}