import { Company } from '../entities/company.entity';
import { ExternalProfile } from '../entities/external-profile.entity';
import { ResponseCompanyProfileDto } from './response-company.dto';

export class ProfileResponseDto {
  companyId: string;
  companyName: string;
  companyType: string;
  nationality: string | null;
  companyEmail: string | null;
  companyPhone: string | null;
  companyLocation: string;
  companyAddress: string | null;
  tinNumber: string;
  vatNumber: string | null;
  fanNumber: string | null;

  companyProfiles: ResponseCompanyProfileDto[];

  licenceNumber: string | null;
  statusDescription: string | null;
  dateRegistered: string | null;
  renewedFrom: string | null;
  renewalDate: string | null;
  renewedTo: string | null;
  region: string | null;
  zone: string | null;
  woreda: string | null;
  kebele: string | null;
  houseNo: string | null;
  etradePhone: string | null;

  contactPersonName: string | null;
  contactPersonPosition: string | null;
  contactPersonEmail: string | null;
  contactPersonPhone: string | null;
  generalManagerName: string | null;
  generalManagerEmail: string | null;
  generalManagerPhone: string | null;

  poaName: string | null;
  poaPhone: string | null;
  poaEmail: string | null;
  poaLocation: string | null;
  poaAddress: string | null;

  profileId: string;

  constructor(profile: ExternalProfile, company: Company) {
    this.companyId = company.id;
    this.companyName = company.name;
    this.companyType = company.type;
    this.nationality = company.nationality ?? null;
    this.companyProfiles =
      company.companyProfiles?.map((p) => new ResponseCompanyProfileDto(p)) ??
      [];
    this.companyEmail = company.email ?? null;
    this.companyPhone = company.phone ?? null;
    this.companyLocation = company.country;
    this.companyAddress = company.address ?? null;
    this.tinNumber = company.tin;
    this.vatNumber = company.vatNumber ?? null;
    this.fanNumber = company.fanNumber ?? null;
    this.profileId = profile.id;

    this.licenceNumber = company.licenceNumber ?? null;
    this.statusDescription = company.statusDescription ?? null;
    this.dateRegistered = company.dateRegistered ?? null;
    this.renewedFrom = company.renewedFrom ?? null;
    this.renewalDate = company.renewalDate ?? null;
    this.renewedTo = company.renewedTo ?? null;
    this.region = company.region ?? null;
    this.zone = company.zone ?? null;
    this.woreda = company.woreda ?? null;
    this.kebele = company.kebele ?? null;
    this.houseNo = company.houseNo ?? null;
    this.etradePhone = company.etradePhone ?? null;

    const attrs = company.attributes ?? {};
    this.contactPersonName = attrs.contactPersonName ?? null;
    this.contactPersonPosition = attrs.contactPersonPosition ?? null;
    this.contactPersonEmail = attrs.contactPersonEmail ?? null;
    this.contactPersonPhone = attrs.contactPersonPhone ?? null;
    this.generalManagerName = attrs.generalManagerName ?? null;
    this.generalManagerEmail = attrs.generalManagerEmail ?? null;
    this.generalManagerPhone = attrs.generalManagerPhone ?? null;
    this.poaName = attrs.poaName ?? null;
    this.poaPhone = attrs.poaPhone ?? null;
    this.poaEmail = attrs.poaEmail ?? null;
    this.poaLocation = attrs.poaLocation ?? null;
    this.poaAddress = attrs.poaAddress ?? null;
  }
}
