import { Result, ValueObject } from '@modules/shared';

interface QualityScoreProps {
  value: number;
}

export class QualityScore extends ValueObject<QualityScoreProps> {
  get value(): number { return this.props.value; }

  static create(value: number): Result<QualityScore, string> {
    if (value < 0 || value > 100) {
      return Result.err('Điểm chất lượng phải từ 0 đến 100');
    }
    const rounded = Math.round(value * 10) / 10; // 1 decimal place
    return Result.ok(new QualityScore({ value: rounded }));
  }

  /** Create from a raw database value (trusted, no validation). */
  static fromPersistence(value: number): QualityScore {
    return new QualityScore({ value });
  }
}
