import { DomainError } from '@/shared/exceptions'

export class UserId {
  constructor(
    public readonly value: string,
    public readonly accountSequence: string,
  ) {
    if (!value) {
      throw new DomainError('用户ID不能为空')
    }
    if (accountSequence === undefined || accountSequence === null) {
      throw new DomainError('账户序列号不能为空')
    }
  }

  static create(value: string, accountSequence: string): UserId {
    return new UserId(value, accountSequence)
  }

  equals(other: UserId): boolean {
    return this.value === other.value && this.accountSequence === other.accountSequence
  }

  toString(): string {
    return this.value
  }
}

export class AdminUserId {
  constructor(
    public readonly value: string,
    public readonly accountSequence: string,
  ) {
    if (!value) {
      throw new DomainError('管理员ID不能为空')
    }
    // 管理员账户序列号可以为空（管理员token没有accountSequence字段）
    // 使用 'ADMIN' 作为默认值
  }

  static create(value: string, accountSequence?: string): AdminUserId {
    return new AdminUserId(value, accountSequence || 'ADMIN')
  }

  equals(other: AdminUserId): boolean {
    return this.value === other.value && this.accountSequence === other.accountSequence
  }

  toString(): string {
    return this.value
  }
}
