import {
  CompanyKind,
  CompanyStatus,
  CompanyType,
} from "../../modules/companies/entities/company.entity";
import {
  ProfileStatus,
  ProfileType,
} from "../../modules/companies/entities/company-profile.entity";

/**
 * Canonical list of seeded Ethiopian government entities. Government bookings
 * are billed to one of these (with an explicit importer/exporter profile)
 * instead of carrying a null company + free-text institution.
 *
 * IDs are fixed so the seeder is idempotent and the matching migration
 * (1821000000003-AddCompanyKindAndGovBookingLinks) can backfill legacy rows to
 * the same companies. The migration mirrors these rows in raw SQL — keep both
 * in sync when adding new entities.
 */

export const GOV_COMPANY_TYPE = CompanyType.Customer;
export const GOV_COMPANY_KIND = CompanyKind.Government;
export const GOV_COMPANY_STATUS = CompanyStatus.Active;
export const GOV_PROFILE_STATUS = ProfileStatus.Active;

export interface GovProfileSeed {
  id: string;
  type: ProfileType;
  reference: string;
}

export interface GovCompanySeed {
  id: string;
  name: string;
  tin: string;
  email: string;
  phone: string;
  profiles: GovProfileSeed[];
}

const importExport = (
  index: number,
  importerId: string,
  exporterId: string,
): GovProfileSeed[] => [
  {
    id: importerId,
    type: ProfileType.importer,
    reference: `IM-9000${index}`,
  },
  {
    id: exporterId,
    type: ProfileType.exporter,
    reference: `EX-9000${index}`,
  },
];

export const GOV_COMPANIES: GovCompanySeed[] = [
  {
    id: "0a1b0001-0000-4000-8000-000000000001",
    name: "Federal Government of Ethiopia",
    tin: "0000000001",
    email: "procurement@gov.et",
    phone: "+251111000001",
    profiles: importExport(
      1,
      "0b1c0001-0000-4000-8000-000000000001",
      "0b1c0001-0000-4000-8000-000000000002",
    ),
  },
  {
    id: "0a1b0002-0000-4000-8000-000000000002",
    name: "Ministry of National Defense",
    tin: "0000000002",
    email: "logistics@mod.gov.et",
    phone: "+251111000002",
    profiles: importExport(
      2,
      "0b1c0002-0000-4000-8000-000000000001",
      "0b1c0002-0000-4000-8000-000000000002",
    ),
  },
  {
    id: "0a1b0003-0000-4000-8000-000000000003",
    name: "Ethiopian Roads Administration",
    tin: "0000000003",
    email: "supply@era.gov.et",
    phone: "+251111000003",
    profiles: importExport(
      3,
      "0b1c0003-0000-4000-8000-000000000001",
      "0b1c0003-0000-4000-8000-000000000002",
    ),
  },
  {
    id: "0a1b0004-0000-4000-8000-000000000004",
    name: "Ministry of Agriculture",
    tin: "0000000004",
    email: "imports@moa.gov.et",
    phone: "+251111000004",
    profiles: importExport(
      4,
      "0b1c0004-0000-4000-8000-000000000001",
      "0b1c0004-0000-4000-8000-000000000002",
    ),
  },
  {
    id: "0a1b0005-0000-4000-8000-000000000005",
    name: "Ministry of Trade and Regional Integration",
    tin: "0000000005",
    email: "trade@motri.gov.et",
    phone: "+251111000005",
    profiles: importExport(
      5,
      "0b1c0005-0000-4000-8000-000000000001",
      "0b1c0005-0000-4000-8000-000000000002",
    ),
  },
  {
    id: "0a1b0006-0000-4000-8000-000000000006",
    name: "Ethiopian Disaster Risk Management Commission",
    tin: "0000000006",
    email: "relief@edrmc.gov.et",
    phone: "+251111000006",
    profiles: importExport(
      6,
      "0b1c0006-0000-4000-8000-000000000001",
      "0b1c0006-0000-4000-8000-000000000002",
    ),
  },
];

/** Fallback entity used to backfill legacy government / null-company bookings. */
export const DEFAULT_GOV_COMPANY = GOV_COMPANIES[0];
export const DEFAULT_GOV_IMPORTER_PROFILE = GOV_COMPANIES[0].profiles[0];
