"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateRecruitmentTables1781050000000 = void 0;
class CreateRecruitmentTables1781050000000 {
    constructor() {
        this.name = 'CreateRecruitmentTables1781050000000';
    }
    async up(queryRunner) {
        const ownerTable = await queryRunner.getTable('owner');
        const hasSlug = ownerTable?.columns.some((column) => column.name === 'slug');
        if (!hasSlug) {
            await queryRunner.query(`ALTER TABLE \`owner\` ADD \`slug\` varchar(191) NULL AFTER \`username\``);
        }
        await queryRunner.query(`
      CREATE TABLE IF NOT EXISTS \`job_postings\` (
        \`id\` varchar(36) NOT NULL,
        \`title\` varchar(191) NOT NULL,
        \`slug\` varchar(191) NOT NULL,
        \`short_description\` varchar(500) NOT NULL DEFAULT 'NT/APL',
        \`salary_range\` varchar(191) NOT NULL DEFAULT 'NT/APL',
        \`location\` varchar(191) NOT NULL DEFAULT 'NT/APL',
        \`job_type\` varchar(191) NOT NULL DEFAULT 'NT/APL',
        \`experience\` varchar(191) NOT NULL DEFAULT 'NT/APL',
        \`department_id\` varchar(191) NULL,
        \`deadline\` datetime(3) NULL,
        \`vacancy_count\` int NOT NULL DEFAULT 1,
        \`role_overview\` json NULL,
        \`basics_benefits\` json NULL,
        \`what_youll_do\` json NULL,
        \`what_were_looking_for\` json NULL,
        \`banner_image\` json NULL,
        \`icon_image\` json NULL,
        \`categories\` json NULL,
        \`tags\` json NULL,
        \`status\` enum('draft','published','closed') NOT NULL DEFAULT 'draft',
        \`record_status\` enum('active','inactive','deleted') NOT NULL DEFAULT 'active',
        \`owner_id\` varchar(191) NOT NULL,
        \`created_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
        \`updated_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
        PRIMARY KEY (\`id\`),
        UNIQUE INDEX \`IDX_job_postings_owner_slug\` (\`owner_id\`, \`slug\`),
        INDEX \`IDX_job_postings_owner\` (\`owner_id\`),
        INDEX \`IDX_job_postings_department\` (\`department_id\`)
      ) ENGINE=InnoDB
    `);
        await queryRunner.query(`
      CREATE TABLE IF NOT EXISTS \`job_applications\` (
        \`id\` varchar(36) NOT NULL,
        \`job_posting_id\` varchar(191) NOT NULL,
        \`full_name\` varchar(191) NOT NULL,
        \`email\` varchar(191) NOT NULL,
        \`phone\` varchar(191) NOT NULL DEFAULT 'NT/APL',
        \`location\` varchar(191) NOT NULL DEFAULT 'NT/APL',
        \`photo_url\` json NULL,
        \`experience_years\` int NOT NULL DEFAULT 0,
        \`resume\` json NULL,
        \`skills\` json NULL,
        \`work_history\` json NULL,
        \`status\` enum('applied','screening','interview','offer','rejected','hired','archived') NOT NULL DEFAULT 'applied',
        \`source\` enum('public_form','public_api','manual') NOT NULL DEFAULT 'manual',
        \`applied_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
        \`interview_at\` datetime(3) NULL,
        \`offer_status\` varchar(191) NULL,
        \`start_date\` datetime(3) NULL,
        \`notes\` text NULL,
        \`owner_id\` varchar(191) NOT NULL,
        \`created_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
        \`updated_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
        PRIMARY KEY (\`id\`),
        INDEX \`IDX_job_applications_owner\` (\`owner_id\`),
        INDEX \`IDX_job_applications_job\` (\`job_posting_id\`),
        INDEX \`IDX_job_applications_status\` (\`status\`)
      ) ENGINE=InnoDB
    `);
        await queryRunner.query(`
      CREATE TABLE IF NOT EXISTS \`recruitment_tasks\` (
        \`id\` varchar(36) NOT NULL,
        \`application_id\` varchar(191) NOT NULL,
        \`title\` varchar(191) NOT NULL,
        \`description\` text NULL,
        \`due_date\` datetime(3) NULL,
        \`status\` enum('pending','submitted','reviewed') NOT NULL DEFAULT 'pending',
        \`public_token\` varchar(191) NOT NULL,
        \`submission\` json NULL,
        \`owner_id\` varchar(191) NOT NULL,
        \`created_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
        \`updated_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
        PRIMARY KEY (\`id\`),
        UNIQUE INDEX \`IDX_recruitment_tasks_token\` (\`public_token\`),
        INDEX \`IDX_recruitment_tasks_application\` (\`application_id\`)
      ) ENGINE=InnoDB
    `);
        await queryRunner.query(`
      CREATE TABLE IF NOT EXISTS \`tenant_api_keys\` (
        \`id\` varchar(36) NOT NULL,
        \`name\` varchar(191) NOT NULL,
        \`key_prefix\` varchar(191) NOT NULL,
        \`secret_hash\` varchar(191) NOT NULL,
        \`status\` enum('active','revoked') NOT NULL DEFAULT 'active',
        \`last_used_at\` datetime(3) NULL,
        \`owner_id\` varchar(191) NOT NULL,
        \`created_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
        \`updated_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
        PRIMARY KEY (\`id\`),
        INDEX \`IDX_tenant_api_keys_owner\` (\`owner_id\`),
        INDEX \`IDX_tenant_api_keys_prefix\` (\`key_prefix\`)
      ) ENGINE=InnoDB
    `);
    }
    async down(queryRunner) {
        await queryRunner.query('DROP TABLE IF EXISTS `tenant_api_keys`');
        await queryRunner.query('DROP TABLE IF EXISTS `recruitment_tasks`');
        await queryRunner.query('DROP TABLE IF EXISTS `job_applications`');
        await queryRunner.query('DROP TABLE IF EXISTS `job_postings`');
        const ownerTable = await queryRunner.getTable('owner');
        const hasSlug = ownerTable?.columns.some((column) => column.name === 'slug');
        if (hasSlug) {
            await queryRunner.query('ALTER TABLE `owner` DROP COLUMN `slug`');
        }
    }
}
exports.CreateRecruitmentTables1781050000000 = CreateRecruitmentTables1781050000000;
//# sourceMappingURL=1781050000000-CreateRecruitmentTables.js.map