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

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

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

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

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