/**
 * Carriers Seed Data
 *
 * Seeds the 5 major shipping carriers
 */

import { v4 as uuidv4 } from 'uuid';

export interface CarrierSeed {
  id: string;
  name: string;
  code: string;
  scac: string;
  logoUrl: string;
  website: string;
  supportsApi: boolean;
  isActive: boolean;
}

export const carrierSeeds: CarrierSeed[] = [
  {
    id: uuidv4(),
    name: 'Maersk Line',
    code: 'MAERSK',
    scac: 'MAEU',
    logoUrl: 'https://www.maersk.com/~/media/maersk/logos/maersk-logo.svg',
    website: 'https://www.maersk.com',
    supportsApi: true,
    isActive: true,
  },
  {
    id: uuidv4(),
    name: 'Mediterranean Shipping Company (MSC)',
    code: 'MSC',
    scac: 'MSCU',
    logoUrl: 'https://www.msc.com/themes/custom/msc_theme/logo.svg',
    website: 'https://www.msc.com',
    supportsApi: false,
    isActive: true,
  },
  {
    id: uuidv4(),
    name: 'CMA CGM',
    code: 'CMA_CGM',
    scac: 'CMDU',
    logoUrl: 'https://www.cma-cgm.com/static/img/logo.svg',
    website: 'https://www.cma-cgm.com',
    supportsApi: false,
    isActive: true,
  },
  {
    id: uuidv4(),
    name: 'Hapag-Lloyd',
    code: 'HAPAG_LLOYD',
    scac: 'HLCU',
    logoUrl: 'https://www.hapag-lloyd.com/etc/designs/hlag/images/logo.svg',
    website: 'https://www.hapag-lloyd.com',
    supportsApi: false,
    isActive: true,
  },
  {
    id: uuidv4(),
    name: 'Ocean Network Express (ONE)',
    code: 'ONE',
    scac: 'ONEY',
    logoUrl: 'https://www.one-line.com/themes/custom/one/logo.svg',
    website: 'https://www.one-line.com',
    supportsApi: false,
    isActive: true,
  },
];

/**
 * Get SQL INSERT statement for carriers
 */
export function getCarriersInsertSQL(): string {
  const values = carrierSeeds
    .map(
      carrier =>
        `('${carrier.id}', '${carrier.name}', '${carrier.code}', '${carrier.scac}', ` +
        `'${carrier.logoUrl}', '${carrier.website}', NULL, ${carrier.isActive}, ${carrier.supportsApi}, NOW(), NOW())`
    )
    .join(',\n    ');

  return `
    INSERT INTO "carriers" (
      "id", "name", "code", "scac", "logo_url", "website",
      "api_config", "is_active", "supports_api", "created_at", "updated_at"
    ) VALUES
    ${values}
    ON CONFLICT ("code") DO NOTHING;
  `;
}
