<?php

namespace KupShop\SKEETBundle\Resources\upgrade;

class SKEETUpgrade extends \UpgradeNew
{
    public function check_EETSentPayment()
    {
        return $this->checkTableExists('sk_eet_payment');
    }

    /** EET: Create table for sent SK EET payments */
    public function upgrade_EETSentPayment()
    {
        sqlQuery(
            'CREATE TABLE sk_eet_payment (
                id INT AUTO_INCREMENT NOT NULL PRIMARY KEY, 
                id_order INT UNSIGNED DEFAULT NULL, 
                id_payment INT DEFAULT NULL, 
                date_sent DATETIME NOT NULL, 
                date_confirmed DATETIME DEFAULT NULL,
            INDEX IDX_A6D4C13S65DA13C2 (id_order), 
            INDEX IDX_H654TNM6TA1VDF3A (id_payment));
            
            ALTER TABLE sk_eet_payment ADD CONSTRAINT IDXC_A6D4C13S65DA13C2 FOREIGN KEY (id_order) REFERENCES orders (id) ON DELETE CASCADE;
            ALTER TABLE sk_eet_payment ADD CONSTRAINT IDXC_H654TNM6TA1VDF3A FOREIGN KEY (id_payment) REFERENCES order_payments (id) ON DELETE CASCADE;
        ');
        $this->upgradeOK();
    }

    public function check_OkpAndUidColumn()
    {
        return $this->checkColumnExists('sk_eet_payment', 'uid') && $this->checkColumnExists('sk_eet_payment', 'okp');
    }

    /** EET: Create column uid and okp for sent SK EET payments */
    public function upgrade_OkpAndUidColumn()
    {
        sqlQuery('
            ALTER TABLE sk_eet_payment 
                ADD COLUMN uid VARCHAR(50) DEFAULT NULL AFTER id_payment, 
                ADD COLUMN okp VARCHAR(50) DEFAULT NULL AFTER uid
        ');
        $this->upgradeOK();
    }
}
