"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LeaveTypeDayOff1781040000000 = void 0;
const DAY_OFF_LEAVE_TYPES = [
    'annual',
    'sick',
    'casual',
    'maternity',
    'paternity',
    'personal',
    'compensatory',
    'unpaid',
    'day_off',
];
const LEGACY_LEAVE_TYPES = [
    'annual',
    'sick',
    'casual',
    'maternity',
    'paternity',
    'personal',
    'compensatory',
    'unpaid',
];
function leaveTypeEnumIncludes(columnType, value) {
    return typeof columnType === 'string' && columnType.includes(`'${value}'`);
}
class LeaveTypeDayOff1781040000000 {
    constructor() {
        this.name = 'LeaveTypeDayOff1781040000000';
    }
    async up(queryRunner) {
        const table = await queryRunner.getTable('leaves');
        const leaveTypeColumn = table?.columns.find((column) => column.name === 'leave_type');
        if (leaveTypeEnumIncludes(leaveTypeColumn?.type, 'day_off')) {
            return;
        }
        await queryRunner.query(`
      ALTER TABLE \`leaves\`
        MODIFY COLUMN \`leave_type\` enum (
          '${DAY_OFF_LEAVE_TYPES.join("','")}'
        ) NOT NULL DEFAULT 'annual'
    `);
    }
    async down(queryRunner) {
        const table = await queryRunner.getTable('leaves');
        const leaveTypeColumn = table?.columns.find((column) => column.name === 'leave_type');
        if (!leaveTypeEnumIncludes(leaveTypeColumn?.type, 'day_off')) {
            return;
        }
        await queryRunner.query(`
      ALTER TABLE \`leaves\`
        MODIFY COLUMN \`leave_type\` enum (
          '${LEGACY_LEAVE_TYPES.join("','")}'
        ) NOT NULL DEFAULT 'annual'
    `);
    }
}
exports.LeaveTypeDayOff1781040000000 = LeaveTypeDayOff1781040000000;
//# sourceMappingURL=1781040000000-LeaveTypeDayOff.js.map