import {
  Organization,
  OrganizationAddress,
  OrganizationDocument,
} from '@domain/entities/organization.entity';
import {
  OrganizationResponseDto,
  OrganizationDocumentDto,
  AddressDto,
} from '../dto/organization.dto';

/**
 * Organization Mapper
 *
 * Maps between Organization domain entities and DTOs
 */
export class OrganizationMapper {
  /**
   * Convert Organization entity to DTO
   */
  static toDto(organization: Organization): OrganizationResponseDto {
    return {
      id: organization.id,
      name: organization.name,
      type: organization.type,
      scac: organization.scac,
      siren: organization.siren,
      eori: organization.eori,
      contact_phone: organization.contactPhone,
      contact_email: organization.contactEmail,
      address: this.mapAddressToDto(organization.address),
      logoUrl: organization.logoUrl,
      documents: organization.documents.map(doc => this.mapDocumentToDto(doc)),
      siret: organization.siret,
      siretVerified: organization.siretVerified,
      statusBadge: organization.statusBadge,
      isActive: organization.isActive,
      createdAt: organization.createdAt,
      updatedAt: organization.updatedAt,
    };
  }

  /**
   * Convert array of Organization entities to DTOs
   */
  static toDtoArray(organizations: Organization[]): OrganizationResponseDto[] {
    return organizations.map(org => this.toDto(org));
  }

  /**
   * Map Address entity to DTO
   */
  private static mapAddressToDto(address: OrganizationAddress): AddressDto {
    return {
      street: address.street,
      city: address.city,
      state: address.state,
      postalCode: address.postalCode,
      country: address.country,
    };
  }

  /**
   * Map Document entity to DTO
   */
  private static mapDocumentToDto(document: OrganizationDocument): OrganizationDocumentDto {
    return {
      id: document.id,
      type: document.type,
      name: document.name,
      url: document.url,
      uploadedAt: document.uploadedAt,
    };
  }

  /**
   * Map DTO Address to domain Address
   */
  static mapDtoToAddress(dto: AddressDto): OrganizationAddress {
    return {
      street: dto.street,
      city: dto.city,
      state: dto.state,
      postalCode: dto.postalCode,
      country: dto.country,
    };
  }
}
