import {
  Company,
  CompanyType,
  CompanyStatus,
  CompanyNationality,
} from '../entities/company.entity';
import {
  BusinessLicenseFile,
  CompanyProfile,
} from '../entities/company-profile.entity';
import { ResponseExternalProfileDto } from './response-external-profile.dto';

export class ResponseCompanyProfileDto {
  id: string;
  companyId: string;
  type: string;
  reference: string;
  status: string;
  /** @deprecated Superseded by licenseFiles. Kept for back-compat. */
  businessLicense?: string | null;
  /** Business-license documents stored on the profile (multi-file). */
  licenseFiles: BusinessLicenseFile[];
  attributes?: Record<string, any> | null;
  createdAt: Date;
  updatedAt: Date;

  constructor(profile: CompanyProfile) {
    this.id = profile.id;
    this.companyId = profile.companyId;
    this.type = profile.type;
    this.reference = profile.reference;
    this.status = profile.status;
    this.businessLicense = profile.businessLicense;
    this.licenseFiles = profile.businessLicenseFiles ?? [];
    this.attributes = profile.attributes;
    this.createdAt = profile.createdAt;
    this.updatedAt = profile.updatedAt;
  }
}

export class ResponseCompanyDto {
  id: string;
  name: string;
  type: CompanyType;
  status: CompanyStatus;
  nationality?: CompanyNationality | null;
  tin: string;
  vatNumber?: string | null;
  fanNumber?: string | null;
  country: string;
  address?: string | null;
  phone?: string | null;
  email?: string | null;
  website?: string | null;
  attributes?: Record<string, any> | null;
  profiles?: ResponseExternalProfileDto[];
  companyProfiles?: ResponseCompanyProfileDto[];
  createdAt: Date;
  updatedAt: Date;

  constructor(company: Company) {
    this.id = company.id;
    this.name = company.name;
    this.type = company.type;
    this.status = company.status;
    this.nationality = company.nationality ?? null;
    this.tin = company.tin;
    this.vatNumber = company.vatNumber;
    this.fanNumber = company.fanNumber;
    this.country = company.country;
    this.address = company.address;
    this.phone = company.phone;
    this.email = company.email;
    this.website = company.website;
    this.attributes = company.attributes;
    this.profiles = company.profiles?.map((p) => new ResponseExternalProfileDto(p));
    this.companyProfiles = company.companyProfiles?.map(
      (p) => new ResponseCompanyProfileDto(p),
    );
    this.createdAt = company.createdAt;
    this.updatedAt = company.updatedAt;
  }
}
