// Imports here
import { ITestData } from "@business-logic/types/ITestData";
import { VehicleDamage, AppointmentType, VehicleLookupType } from "@business-logic/types/Enums";
import TestCase from "@business-logic/types/TestCase";
import { getNextWeekday } from "@impl/utils/DateUtils";
import { faker } from "@faker-js/faker";
import { defaultTestData } from "@business-logic/constants/DefaultTestData";

// Unserviceable zip (alert) - Combined test cases for all lookup types
const nextWeekday = getNextWeekday();

const baseUnserviceableZipData: Partial<ITestData> = {
    ...defaultTestData,  // Start with all defaults

    // Override specific fields with test-specific data
    customerDetails: {
        ...defaultTestData.customerDetails!,
        firstName: faker.person.firstName(),
        lastName: faker.person.lastName(),
        address: {
            street: faker.location.streetAddress(),
            city: 'Saco',
            state: 'Montana',
            postalCode: '59261',
            country: 'United States'
        }
    },
    vehicleDamage: [
        VehicleDamage.WindshieldCrack
    ],
    appointmentDetails: {
        serviceLocation: AppointmentType.DropOff,
        appointmentDate: nextWeekday
    },
    alertFlags: {
        isUnserviceableZip: true
    }
};

interface LookupTestCase {
    type: VehicleLookupType;
    vehicleDetails: {
        year: string;
        make: string;
        model: string;
        style: string;
        licensePlateNumber?: string;
        licensePlateState?: string;
        vin?: string;
    };
    enterFunnelWithZip?: boolean;
    customerDetails?: {
        address: {
            street: string;
            city: string;
            state: string;
            postalCode: string;
            country: string;
        };
    };
    tag: string;
}

const lookupTypesToTest: LookupTestCase[] = [
    {
        type: VehicleLookupType.Zip,
        vehicleDetails: {
            year: '2020',
            make: 'Acura',
            model: 'ILX',
            style: '4 door sedan'
        },
        tag: 'Zip'
    },
    {
        type: VehicleLookupType.Vin,
        vehicleDetails: {
            year: '2019',
            make: 'Toyota',
            model: 'C-HR',
            style: '4 door hatchback',
            vin: 'NMTKHMBX5KR086519'
        },
        tag: 'Vin'
    }
];

const unserviceableZipTests: TestCase[] = [];

// Generate test cases for each lookup type
lookupTypesToTest.forEach((lookupType, index) => {
    const testData = {
        ...baseUnserviceableZipData,
        vehicleDetails: {
            ...lookupType.vehicleDetails,
            vehicleLookupType: lookupType.type
        },
        enterFunnelWithZip: lookupType.enterFunnelWithZip
    };

    // Handle special case for Address lookup which has different customer details
    if (lookupType.type === VehicleLookupType.Address && lookupType.customerDetails) {
        testData.customerDetails = {
            ...baseUnserviceableZipData.customerDetails!,
            address: lookupType.customerDetails.address
        };
    }

    const tc = new TestCase({
        name: `alert0005 ${lookupType.tag} Lookup Unserviceable zip`,
        tags: ['@Alert', `@UnserviceableZip_${lookupType.tag}`, '@test_report'],
        testData: testData
    }, undefined, `UnserviceableZip_${lookupType.tag}`);

    unserviceableZipTests.push(tc);
});

export default unserviceableZipTests;