"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateSeedMigrations = generateSeedMigrations;
const generator_1 = require("@postxl/generator");
const schema_1 = require("@postxl/schema");
function generateSeedMigrations(context) {
    const userModel = context.models.get(schema_1.standardModelName_User);
    if (!userModel) {
        throw new Error(`User model is required for seed migrations!`);
    }
    const imports = generator_1.ImportGenerator
        //
        .from(context.seedData.seedMigrations.location)
        .addType(context.seedData.migrationTypes.summary)
        .add(userModel.seedData.dataVariable);
    return /* ts */ `
import { resolve } from 'node:path'

${imports.generate()}

export const ${context.seedData.seedMigrations.name}: ${context.seedData.migrationTypes.summary.name}[] = [
  {
    order: 1,
    type: '${context.seedData.migrationTypes.excel.discriminant}',
    name: 'Import data from Excel',
    description: \`Initial seed with the data from the Excel file. 
      Note that for the first seeding we can use "excel" instead of "excel-delta",
      as we do not need to detect the delta as the database is blank.
      For later seeding steps that occur in a running production, it is strongly recommended 
      to use "excel-delta" to ensure that a consistency check is performed!\`,
    filename: resolve(
      __dirname, 
      // The location of the Excel file needs to be outside the source folder, as Typescript does not copy it to the dist folder!
      // Important: Ensure that the file is also copied to the right location when building the docker image!
      '../../../../../../.${context.seedData.excelTemplate.projectRootPath}'),
  },

  {
    order: 2,
    type: '${context.seedData.migrationTypes.customAction.discriminant}',
    name: 'Example for custom action',
    description: \`This example shows how to trigger a custom action. 
      In this case, we import the users from the seed data.
      As the users are already included in the seed Excel in the above step,
      this will not result in any data change.\`,
    action: {
      scope: 'import',
      type: 'data',
      payload: {
        //TODO: We need to extend the decoders and import service to support raw, unflattened data!
        users: ${userModel.seedData.dataVariable.name} as any, // NOSONAR
      },
    },
  },
]`;
}
//# sourceMappingURL=seed-migrations.generator.js.map