"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const core_1 = require("@nestjs/core");
const common_1 = require("@nestjs/common");
const path_1 = require("path");
const app_module_1 = require("../app.module");
const car_listing_service_1 = require("../appapi/carlisting/car-listing.service");
const car_catalog_import_util_1 = require("../appapi/carlisting/car-catalog-import.util");
async function bootstrap() {
    const logger = new common_1.Logger("ImportCarCatalog");
    const workbookArg = process.argv[2];
    const workbookPath = (0, path_1.resolve)(workbookArg || "Middle-East-Car-Database-Make-Model-Year-Engine-Specs.xlsx");
    logger.log(`Reading car catalog workbook from ${workbookPath}`);
    const entries = (0, car_catalog_import_util_1.importCarCatalogWorkbook)(workbookPath);
    logger.log(`Parsed ${entries.length} catalog entries from workbook`);
    const app = await core_1.NestFactory.createApplicationContext(app_module_1.AppModule, {
        logger: ["error", "warn", "log"],
    });
    try {
        const carListingService = app.get(car_listing_service_1.CarListingService);
        await carListingService.importCatalogEntries(entries);
        const totalEntries = await carListingService.getCatalogEntryCount();
        logger.log(`Car catalog import completed. Database now contains ${totalEntries} entries.`);
    }
    finally {
        await app.close();
    }
}
bootstrap().catch((error) => {
    const logger = new common_1.Logger("ImportCarCatalog");
    logger.error(error?.message || "Car catalog import failed.", error?.stack);
    process.exit(1);
});
//# sourceMappingURL=import-car-catalog.js.map