import { Company } from '../entities/company.entity';
import { ExternalProfile } from '../entities/external-profile.entity';
import {
  ChangeRequestStatus,
  CompanyChangeRequest,
} from '../entities/company-change-request.entity';
import { ResponseCompanyDto } from './response-company.dto';
import { ResponseExternalProfileDto } from './response-external-profile.dto';

export class CompanyInfoResponseDto {
  profile: ResponseExternalProfileDto;
  company: ResponseCompanyDto;
  /**
   * Open profile-edit review, if any. Drives the portal-wide lock (pending →
   * settings + new-contract/booking creation disabled) and the reapply banner.
   */
  review: {
    status: 'pending' | 'rejected';
    note: string | null;
  } | null;

  constructor(
    profile: ExternalProfile,
    company: Company,
    changeRequest?: CompanyChangeRequest | null,
  ) {
    this.profile = new ResponseExternalProfileDto(profile);
    this.company = new ResponseCompanyDto(company);

    const open =
      changeRequest &&
      (changeRequest.status === ChangeRequestStatus.Pending ||
        changeRequest.status === ChangeRequestStatus.Rejected)
        ? changeRequest
        : null;
    this.review = open
      ? {
          status: open.status as 'pending' | 'rejected',
          note: open.note ?? null,
        }
      : null;
  }
}
