<?php

class Migration_20241122060904_update_key_types
{
    public static function up(PDO $pdo)
    {
        $sql = "
            INSERT INTO key_type (name, `desc`) VALUES ('CallerID+Code', 'As an extra security measure is a combonation of CallerID and Key_Code. This will require Dual Authentication to be granted access.');
        ";

        $pdo->exec($sql);

        $sql1 = "
            ALTER TABLE `visitors`
            MODIFY COLUMN `key_type` ENUM('CallerID','Key_Code','Magic_Password','CallerID+Code'),
            ADD COLUMN `cidphone` VARCHAR(10) AFTER `magic_password`,
            ADD COLUMN `cidcode` INT AFTER `cidphone`;
        ";

        $pdo->exec($sql1);

        $sql2 = "
            ALTER TABLE `vendors`
            MODIFY COLUMN `key_type` ENUM('CallerID','Key_Code','Magic_Password','CallerID+Code'),
            ADD COLUMN `cidphone` VARCHAR(10) AFTER `magic_password`,
            ADD COLUMN `cidcode` INT AFTER `cidphone`;
        ";

        $pdo->exec($sql2);

    }

    public static function down(PDO $pdo)
    {
        $sql = "
            DELETE FROM key_type WHERE name = 'CallerID+Code';
        ";

        $pdo->exec($sql);

        $sql1 = "
            ALTER TABLE `visitors`,
            DROP COLUMN `cidphone`,
            DROP CLOUMN `cidcode`;
        ";

        $pdo->exec($sql1);

        $sql2 = "
            ALTER TABLE `vendors`,
            DROP COLUMN `cidphone`,
            DROP CLOUMN `cidcode`;
        ";

        $pdo->exec($sql2);
    }
}