import { MigrationInterface, QueryRunner } from "typeorm";

export class UpdateViewDirectorAddPositionSign1765275494909 implements MigrationInterface {
    name = 'UpdateViewDirectorAddPositionSign1765275494909'

    public async up(queryRunner: QueryRunner): Promise<void> {
    //     await queryRunner.query(`CREATE VIEW \`view_director\` AS SELECT 
    //     profile.id AS Id,
    //     profile.prefix AS prefix,
    //     profile.firstName AS firstName,
    //     profile.lastName AS lastName,
    //     profile.citizenId AS citizenId,
    //     profile.position AS position,
    //     profile.keycloak AS keycloakId,
    //     profile.isProbation AS isProbation,
    //     CONCAT(
    //         CASE 
    //             WHEN posMaster.orgChild1Id IS NULL THEN orgRoot.orgRootShortName
    //             WHEN posMaster.orgChild2Id IS NULL THEN orgChild1.orgChild1ShortName
    //             WHEN posMaster.orgChild3Id IS NULL THEN orgChild2.orgChild2ShortName
    //             WHEN posMaster.orgChild4Id IS NULL THEN orgChild3.orgChild3ShortName
    //             ELSE orgChild4.orgChild4ShortName
    //         END,
    //         posMaster.posMasterNo
    //     ) AS posNo,
    //     posMaster.isDirector AS isDirector,
    //     posLevel.posLevelName AS posLevel,
    //     posType.posTypeName AS posType,
    //     posExecutive.posExecutiveName AS posExecutiveName,
    //     orgRoot.isDeputy AS isDeputy,
    //     orgChild1.isOfficer AS isOfficer,
    //     posMaster.orgRevisionId AS orgRevisionId,
    //     posMaster.orgRootId AS orgRootId,
    //     posMaster.orgChild1Id AS orgChild1Id,
    //     posMaster.orgChild2Id AS orgChild2Id,
    //     posMaster.orgChild3Id AS orgChild3Id,
    //     posMaster.orgChild4Id AS orgChild4Id,
    //     posMaster.positionSign AS positionSign,
    //     CONCAT(posMaster.id, profile.id) AS \`key\`,
    //     (
    //       SELECT hrms_organization.acting.actFullNameKeycloakId
    //       FROM hrms_organization.view_director_acting acting
    //       WHERE ((hrms_organization.acting.Id = hrms_organization.posMaster.current_holderId)
    //       AND (hrms_organization.acting.orgRootId = hrms_organization.posMaster.orgRootId)
    //       AND ((hrms_organization.acting.orgChild1Id = hrms_organization.posMaster.orgChild1Id)
    //       OR (hrms_organization.acting.orgChild1Id IS NULL))
    //       AND ((hrms_organization.acting.orgChild2Id = hrms_organization.posMaster.orgChild2Id)
    //       OR (hrms_organization.acting.orgChild2Id IS NULL))
    //       AND ((hrms_organization.acting.orgChild3Id = hrms_organization.posMaster.orgChild3Id)
    //       OR (hrms_organization.acting.orgChild3Id IS NULL))
    //       AND ((hrms_organization.acting.orgChild4Id = hrms_organization.posMaster.orgChild4Id)
    //       OR (hrms_organization.acting.orgChild4Id IS NULL)))
    //       LIMIT 1
    //     ) AS actFullNameKeycloakId,
    //     (
    //       SELECT actFullNameId 
    //       FROM view_director_acting AS acting
    //       WHERE acting.Id = posMaster.current_holderId 
    //       AND acting.orgRootId = posMaster.orgRootId 
    //       AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)
    //       AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)
    //       AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)
    //       AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)
    //       LIMIT 1
    //     ) AS actFullNameId,
    //     (
    //       SELECT actFullName 
    //       FROM view_director_acting AS acting
    //       WHERE acting.Id = posMaster.current_holderId 
    //       AND acting.orgRootId = posMaster.orgRootId 
    //       AND (acting.orgChild1Id = posMaster.orgChild1Id OR acting.orgChild1Id IS NULL)
    //       AND (acting.orgChild2Id = posMaster.orgChild2Id OR acting.orgChild2Id IS NULL)
    //       AND (acting.orgChild3Id = posMaster.orgChild3Id OR acting.orgChild3Id IS NULL)
    //       AND (acting.orgChild4Id = posMaster.orgChild4Id OR acting.orgChild4Id IS NULL)
    //       LIMIT 1
    //     ) AS actFullName
    // FROM
    //     posMaster
    //     JOIN profile ON posMaster.current_holderId = profile.id
    //     LEFT JOIN orgRoot ON posMaster.orgRootId = orgRoot.id
    //     LEFT JOIN orgChild1 ON posMaster.orgChild1Id = orgChild1.id
    //     LEFT JOIN orgChild2 ON posMaster.orgChild2Id = orgChild2.id
    //     LEFT JOIN orgChild3 ON posMaster.orgChild3Id = orgChild3.id
    //     LEFT JOIN orgChild4 ON posMaster.orgChild4Id = orgChild4.id
    //     JOIN posLevel ON profile.posLevelId = posLevel.id
    //     JOIN posType ON profile.posTypeId = posType.id
    //     LEFT JOIN position ON posMaster.id = position.posMasterId
    //     LEFT JOIN posExecutive ON position.posExecutiveId = posExecutive.id
    //     INNER JOIN orgRevision ON posMaster.orgRevisionId = orgRevision.id
    // WHERE
    //     (position.positionIsSelected = TRUE)
    //     AND (orgRevision.orgRevisionIsCurrent = TRUE
    //     AND orgRevision.orgRevisionIsDraft = FALSE)`);
    //     await queryRunner.query(`CREATE VIEW \`view_director_acting\` AS SELECT 
    //     \`profileChild\`.\`id\` AS \`Id\`,
    //     \`profileChild\`.\`prefix\` AS \`prefix\`,
    //     \`profileChild\`.\`firstName\` AS \`firstName\`,
    //     \`profileChild\`.\`lastName\` AS \`lastName\`,
    //     \`profileChild\`.\`citizenId\` AS \`citizenId\`,
    //     \`profileChild\`.\`position\` AS \`position\`,
    //     \`profile\`.\`isProbation\` AS \`isProbation\`,
    //     CONCAT((CASE
    //                 WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRootChild\`.\`orgRootShortName\`
    //                 WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1Child\`.\`orgChild1ShortName\`
    //                 WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2Child\`.\`orgChild2ShortName\`
    //                 WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3Child\`.\`orgChild3ShortName\`
    //                 ELSE \`orgChild4Child\`.\`orgChild4ShortName\`
    //             END),
    //             \`posMaster\`.\`posMasterNo\`) AS \`posNo\`,
    //     \`posMasterChild\`.\`isDirector\` AS \`isDirectorChild\`,
    //     \`posMaster\`.\`isDirector\` AS \`isDirector\`,
    //     \`posLevel\`.\`posLevelName\` AS \`posLevel\`,
    //     \`posType\`.\`posTypeName\` AS \`posType\`,
    //     \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`,
    //     \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`,
    //     \`orgChild1\`.\`isOfficer\` AS \`isOfficer\`,
    //     \`posMaster\`.\`orgRevisionId\` AS \`orgRevisionId\`,
    //     \`posMaster\`.\`orgRootId\` AS \`orgRootId\`,
    //     \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`,
    //     \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`,
    //     \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`,
    //     \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`,
    //     \`posMaster\`.\`positionSign\` AS \`positionSign\`,
    //     CONCAT(\`hrms_organization\`.\`posMaster\`.\`id\`,
    //             \`profileChild\`.\`id\`) AS \`key\`,
    //     \`hrms_organization\`.\`profile\`.\`id\` AS \`actFullNameId\`,
    //     \`hrms_organization\`.\`profile\`.\`keycloak\` AS \`actFullNameKeycloakId\`,
    //     CONCAT(\`posMaster\`.\`id\`, \`profileChild\`.\`id\`) AS \`key\`,
    //     \`profile\`.\`id\` AS \`actFullNameId\`,
    //     CONCAT(\`profile\`.\`prefix\`,
    //             \`profile\`.\`firstName\`,
    //             ' ',
    //             \`profile\`.\`lastName\`) AS \`actFullName\`
    // FROM
    //     (((((((((((((((\`posMasterAct\`
    //     JOIN \`posMaster\` \`posMasterChild\` ON ((\`posMasterAct\`.\`posMasterChildId\` = \`posMasterChild\`.\`id\`)))
    //     JOIN \`profile\` \`profileChild\` ON ((\`posMasterChild\`.\`current_holderId\` = \`profileChild\`.\`id\`)))
    //     LEFT JOIN \`orgRoot\` \`orgRootChild\` ON ((\`posMasterChild\`.\`orgRootId\` = \`orgRootChild\`.\`id\`)))
    //     LEFT JOIN \`orgChild1\` \`orgChild1Child\` ON ((\`posMasterChild\`.\`orgChild1Id\` = \`orgChild1Child\`.\`id\`)))
    //     LEFT JOIN \`orgChild2\` \`orgChild2Child\` ON ((\`posMasterChild\`.\`orgChild2Id\` = \`orgChild2Child\`.\`id\`)))
    //     LEFT JOIN \`orgChild3\` \`orgChild3Child\` ON ((\`posMasterChild\`.\`orgChild3Id\` = \`orgChild3Child\`.\`id\`)))
    //     LEFT JOIN \`orgChild4\` \`orgChild4Child\` ON ((\`posMasterChild\`.\`orgChild4Id\` = \`orgChild4Child\`.\`id\`)))
    //     JOIN \`posLevel\` ON ((\`profileChild\`.\`posLevelId\` = \`posLevel\`.\`id\`)))
    //     JOIN \`posType\` ON ((\`profileChild\`.\`posTypeId\` = \`posType\`.\`id\`)))
    //     JOIN \`posMaster\` ON ((\`posMasterAct\`.\`posMasterId\` = \`posMaster\`.\`id\`)))
    //     LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`)))
    //     LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`)))
    //     JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`)))
    //     LEFT JOIN \`position\` ON ((\`posMasterChild\`.\`id\` = \`position\`.\`posMasterId\`)))
    //     LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`)))
    // WHERE
    //     (\`position\`.\`positionIsSelected\` = TRUE)`);
    }
    public async down(queryRunner: QueryRunner): Promise<void> {
        // await queryRunner.query(`DROP VIEW \`view_director\``);
        // await queryRunner.query(`DROP VIEW \`view_director_acting\``);
    }

}
