import type { IValueObject } from '@core/shared/domain';
import { RacingDomainValidationError } from '../errors/RacingDomainError';

export interface TeamRatingDimensionKeyProps {
  value: 'driving' | 'adminTrust';
}

const VALID_DIMENSIONS = ['driving', 'adminTrust'] as const;

export class TeamRatingDimensionKey implements IValueObject<TeamRatingDimensionKeyProps> {
  readonly value: TeamRatingDimensionKeyProps['value'];

  private constructor(value: TeamRatingDimensionKeyProps['value']) {
    this.value = value;
  }

  static create(value: string): TeamRatingDimensionKey {
    if (!value || value.trim().length === 0) {
      throw new RacingDomainValidationError('Team rating dimension key cannot be empty');
    }

    // Strict validation: no leading/trailing whitespace allowed
    if (value !== value.trim()) {
      throw new RacingDomainValidationError(
        `Team rating dimension key cannot have leading or trailing whitespace: "${value}"`
      );
    }

    if (!VALID_DIMENSIONS.includes(value as TeamRatingDimensionKeyProps['value'])) {
      throw new RacingDomainValidationError(
        `Invalid team rating dimension key: ${value}. Valid options: ${VALID_DIMENSIONS.join(', ')}`
      );
    }

    return new TeamRatingDimensionKey(value as TeamRatingDimensionKeyProps['value']);
  }

  get props(): TeamRatingDimensionKeyProps {
    return { value: this.value };
  }

  equals(other: IValueObject<TeamRatingDimensionKeyProps>): boolean {
    return this.value === other.props.value;
  }

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