import { MigrationInterface, QueryRunner } from "typeorm";

export class  $npmConfigName1773906965984 implements MigrationInterface {
    name = ' $npmConfigName1773906965984'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TABLE \`employee_profiles\` (\`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, \`birth_date\` date NULL, \`address\` text NULL, \`phone\` varchar(30) NULL, \`emergency_contact_name\` varchar(100) NULL, \`emergency_contact_phone\` varchar(30) NULL, \`job_title\` varchar(100) NOT NULL, \`contract_type\` varchar(50) NULL, \`skills\` json NULL, \`user_id\` int UNSIGNED NULL, UNIQUE INDEX \`REL_986e309c16f09ce6cc47d674cf\` (\`user_id\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
        await queryRunner.query(`CREATE TABLE \`career_history\` (\`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, \`event_type\` enum ('PROMOTION', 'MUTATION', 'POSTE_CHANGE', 'SALAIRE') NOT NULL, \`description\` text NOT NULL, \`effective_date\` date NOT NULL, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`user_id\` int UNSIGNED NULL, \`created_by\` int UNSIGNED NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
        await queryRunner.query(`CREATE TABLE \`notifications\` (\`id\` bigint UNSIGNED NOT NULL AUTO_INCREMENT, \`type\` enum ('LEAVE_SUBMITTED', 'LEAVE_APPROVED', 'LEAVE_REJECTED', 'LEAVE_CANCELLED', 'LEAVE_REMINDER', 'ANNOUNCEMENT') NOT NULL, \`message\` text NOT NULL, \`link\` varchar(255) NULL, \`is_read\` tinyint NOT NULL DEFAULT 0, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`user_id\` int UNSIGNED NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
        await queryRunner.query(`CREATE TABLE \`audit_logs\` (\`id\` bigint UNSIGNED NOT NULL AUTO_INCREMENT, \`action\` varchar(100) NOT NULL, \`entity_type\` varchar(50) NOT NULL, \`entity_id\` int UNSIGNED NOT NULL, \`old_value\` json NULL, \`new_value\` json NULL, \`ip_address\` varchar(45) NULL, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`user_id\` int UNSIGNED NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
        await queryRunner.query(`CREATE TABLE \`announcements\` (\`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, \`title\` varchar(200) NOT NULL, \`content\` text NOT NULL, \`target\` enum ('all', 'agency', 'team') NOT NULL, \`target_id\` int UNSIGNED NULL, \`published_at\` timestamp NULL, \`is_published\` tinyint NOT NULL DEFAULT 0, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`author_id\` int UNSIGNED NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
        await queryRunner.query(`ALTER TABLE \`employee_profiles\` ADD CONSTRAINT \`FK_986e309c16f09ce6cc47d674cfe\` FOREIGN KEY (\`user_id\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`career_history\` ADD CONSTRAINT \`FK_92f52aaac4c3887d389c0325a93\` FOREIGN KEY (\`user_id\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`career_history\` ADD CONSTRAINT \`FK_5181dddca8094ba68c8c6a9a307\` FOREIGN KEY (\`created_by\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`notifications\` ADD CONSTRAINT \`FK_9a8a82462cab47c73d25f49261f\` FOREIGN KEY (\`user_id\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`audit_logs\` ADD CONSTRAINT \`FK_bd2726fd31b35443f2245b93ba0\` FOREIGN KEY (\`user_id\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`announcements\` ADD CONSTRAINT \`FK_0a13cf0aa1f1a2666699ff473f0\` FOREIGN KEY (\`author_id\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`announcements\` DROP FOREIGN KEY \`FK_0a13cf0aa1f1a2666699ff473f0\``);
        await queryRunner.query(`ALTER TABLE \`audit_logs\` DROP FOREIGN KEY \`FK_bd2726fd31b35443f2245b93ba0\``);
        await queryRunner.query(`ALTER TABLE \`notifications\` DROP FOREIGN KEY \`FK_9a8a82462cab47c73d25f49261f\``);
        await queryRunner.query(`ALTER TABLE \`career_history\` DROP FOREIGN KEY \`FK_5181dddca8094ba68c8c6a9a307\``);
        await queryRunner.query(`ALTER TABLE \`career_history\` DROP FOREIGN KEY \`FK_92f52aaac4c3887d389c0325a93\``);
        await queryRunner.query(`ALTER TABLE \`employee_profiles\` DROP FOREIGN KEY \`FK_986e309c16f09ce6cc47d674cfe\``);
        await queryRunner.query(`DROP TABLE \`announcements\``);
        await queryRunner.query(`DROP TABLE \`audit_logs\``);
        await queryRunner.query(`DROP TABLE \`notifications\``);
        await queryRunner.query(`DROP TABLE \`career_history\``);
        await queryRunner.query(`DROP INDEX \`REL_986e309c16f09ce6cc47d674cf\` ON \`employee_profiles\``);
        await queryRunner.query(`DROP TABLE \`employee_profiles\``);
    }

}
