import { v4 as uuidv4 } from 'uuid'
import { DomainError } from '@/shared/exceptions'

export class AuthorizationId {
  constructor(public readonly value: string) {
    if (!value) {
      throw new DomainError('授权ID不能为空')
    }
  }

  static generate(): AuthorizationId {
    return new AuthorizationId(uuidv4())
  }

  static create(value: string): AuthorizationId {
    return new AuthorizationId(value)
  }

  equals(other: AuthorizationId): boolean {
    return this.value === other.value
  }

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