/**
 * Carrier ORM Mapper
 *
 * Maps between Carrier domain entity and CarrierOrmEntity
 */

import { Carrier, CarrierProps } from '@domain/entities/carrier.entity';
import { CarrierOrmEntity } from '../entities/carrier.orm-entity';

export class CarrierOrmMapper {
  /**
   * Map domain entity to ORM entity
   */
  static toOrm(domain: Carrier): CarrierOrmEntity {
    const orm = new CarrierOrmEntity();
    const props = domain.toObject();

    orm.id = props.id;
    orm.name = props.name;
    orm.code = props.code;
    orm.scac = props.scac;
    orm.logoUrl = props.logoUrl || null;
    orm.website = props.website || null;
    orm.apiConfig = props.apiConfig || null;
    orm.isActive = props.isActive;
    orm.supportsApi = props.supportsApi;
    orm.createdAt = props.createdAt;
    orm.updatedAt = props.updatedAt;

    return orm;
  }

  /**
   * Map ORM entity to domain entity
   */
  static toDomain(orm: CarrierOrmEntity): Carrier {
    const props: CarrierProps = {
      id: orm.id,
      name: orm.name,
      code: orm.code,
      scac: orm.scac,
      logoUrl: orm.logoUrl || undefined,
      website: orm.website || undefined,
      apiConfig: orm.apiConfig || undefined,
      isActive: orm.isActive,
      supportsApi: orm.supportsApi,
      createdAt: orm.createdAt,
      updatedAt: orm.updatedAt,
    };

    return Carrier.fromPersistence(props);
  }

  /**
   * Map array of ORM entities to domain entities
   */
  static toDomainMany(orms: CarrierOrmEntity[]): Carrier[] {
    return orms.map(orm => this.toDomain(orm));
  }
}
