import { ChainTypeEnum } from '../enums';

/**
 * 链类型值对象
 */
export class ChainType {
  private readonly _value: ChainTypeEnum;

  private constructor(value: ChainTypeEnum) {
    this._value = value;
  }

  static create(value: string): ChainType {
    const normalized = value.toUpperCase() as ChainTypeEnum;
    if (!Object.values(ChainTypeEnum).includes(normalized)) {
      throw new Error(`Invalid chain type: ${value}`);
    }
    return new ChainType(normalized);
  }

  static fromEnum(value: ChainTypeEnum): ChainType {
    return new ChainType(value);
  }

  static KAVA(): ChainType {
    return new ChainType(ChainTypeEnum.KAVA);
  }

  static BSC(): ChainType {
    return new ChainType(ChainTypeEnum.BSC);
  }

  get value(): ChainTypeEnum {
    return this._value;
  }

  equals(other: ChainType): boolean {
    return this._value === other._value;
  }

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

  isEVM(): boolean {
    return [ChainTypeEnum.KAVA, ChainTypeEnum.BSC].includes(this._value);
  }
}
