import { UserRating } from '@core/identity/domain/value-objects/UserRating';
import { UserRatingOrmEntity } from '../entities/UserRatingOrmEntity';

/**
 * Mapper: UserRatingOrmMapper
 * 
 * Converts between UserRating value object and UserRatingOrmEntity.
 */
export class UserRatingOrmMapper {
  /**
   * Convert ORM entity to domain value object
   */
  static toDomain(entity: UserRatingOrmEntity): UserRating {
    const props: any = {
      userId: entity.userId,
      driver: entity.driver,
      admin: entity.admin,
      steward: entity.steward,
      trust: entity.trust,
      fairness: entity.fairness,
      overallReputation: entity.overallReputation,
      createdAt: entity.createdAt,
      updatedAt: entity.updatedAt,
    };
    
    if (entity.calculatorVersion !== undefined && entity.calculatorVersion !== null) {
      props.calculatorVersion = entity.calculatorVersion;
    }
    
    return UserRating.restore(props);
  }

  /**
   * Convert domain value object to ORM entity
   */
  static toOrmEntity(domain: UserRating): UserRatingOrmEntity {
    const entity = new UserRatingOrmEntity();
    entity.userId = domain.userId;
    entity.driver = domain.driver;
    entity.admin = domain.admin;
    entity.steward = domain.steward;
    entity.trust = domain.trust;
    entity.fairness = domain.fairness;
    entity.overallReputation = domain.overallReputation;
    if (domain.calculatorVersion !== undefined) {
      entity.calculatorVersion = domain.calculatorVersion;
    }
    entity.createdAt = domain.createdAt;
    entity.updatedAt = domain.updatedAt;
    return entity;
  }
}