import { DomainError, Result, ValueObject, handleDomainError } from "@shared/contexts";

export class AuthUserRole extends ValueObject<string> {
  static ROLE_ADMIN = new AuthUserRole("ROLE_ADMIN");
  static ROLE_USER = new AuthUserRole("ROLE_USER");

  public static create(value: string) {
    switch (value) {
      case "ROLE_ADMIN":
        return Result.ok(AuthUserRole.ROLE_ADMIN);
      case "ROLE_USER":
        return Result.ok(AuthUserRole.ROLE_USER);
      default:
        return Result.fail(handleDomainError(DomainError.INVALID_INPUT_DATA));
    }
  }

  public toPrimitive(): string {
    return this.toString();
  }
}
