/**
 * Test Organizations Seed Data
 *
 * Seeds test organizations for development
 */

export interface OrganizationSeed {
  id: string;
  name: string;
  type: string;
  scac: string | null;
  addressStreet: string;
  addressCity: string;
  addressState: string | null;
  addressPostalCode: string;
  addressCountry: string;
  isActive: boolean;
}

// Fixed UUIDs for consistent seed data across environments
export const DEFAULT_ORG_ID = 'c6042c7b-cffe-4fef-94f6-f27c2d0eb809';
export const DEMO_CARRIER_ID = '462001d1-6829-4554-a4e1-477667edab6b';
export const SAMPLE_SHIPPER_ID = '39e49605-5292-4935-9bff-c4abb547d3b9';

export const organizationSeeds: OrganizationSeed[] = [
  {
    id: DEFAULT_ORG_ID,
    name: 'Test Freight Forwarder Inc.',
    type: 'FREIGHT_FORWARDER',
    scac: null,
    addressStreet: '123 Logistics Avenue',
    addressCity: 'Rotterdam',
    addressState: null,
    addressPostalCode: '3011 AA',
    addressCountry: 'NL',
    isActive: true,
  },
  {
    id: DEMO_CARRIER_ID,
    name: 'Demo Shipping Company',
    type: 'CARRIER',
    scac: 'DEMO',
    addressStreet: '456 Maritime Boulevard',
    addressCity: 'Singapore',
    addressState: null,
    addressPostalCode: '018956',
    addressCountry: 'SG',
    isActive: true,
  },
  {
    id: SAMPLE_SHIPPER_ID,
    name: 'Sample Shipper Ltd.',
    type: 'SHIPPER',
    scac: null,
    addressStreet: '789 Commerce Street',
    addressCity: 'New York',
    addressState: 'NY',
    addressPostalCode: '10004',
    addressCountry: 'US',
    isActive: true,
  },
];

/**
 * Get SQL INSERT statement for organizations
 */
export function getOrganizationsInsertSQL(): string {
  const values = organizationSeeds
    .map(
      org =>
        `('${org.id}', '${org.name}', '${org.type}', ` +
        `${org.scac ? `'${org.scac}'` : 'NULL'}, ` +
        `'${org.addressStreet}', '${org.addressCity}', ` +
        `${org.addressState ? `'${org.addressState}'` : 'NULL'}, ` +
        `'${org.addressPostalCode}', '${org.addressCountry}', ` +
        `NULL, '[]', ${org.isActive}, NOW(), NOW())`
    )
    .join(',\n    ');

  return `
    INSERT INTO "organizations" (
      "id", "name", "type", "scac",
      "address_street", "address_city", "address_state", "address_postal_code", "address_country",
      "logo_url", "documents", "is_active", "created_at", "updated_at"
    ) VALUES
    ${values}
    ON CONFLICT ("name") DO NOTHING;
  `;
}
