<?php

declare(strict_types=1);

namespace External\PompoBundle\Resources\upgrade;

class DataGoUpgrade extends \UpgradeNew
{
    public function check_DataGoOrders(): bool
    {
        return $this->checkTableExists('datago_orders');
    }

    /** Add datago_orders table */
    public function upgrade_DataGoOrders(): void
    {
        sqlQuery('CREATE TABLE IF NOT EXISTS datago_orders (
              id_datago VARCHAR(30) NOT NULL UNIQUE,
              id_order INT(11) UNSIGNED NOT NULL,
              data MEDIUMTEXT DEFAULT NULL,
              CONSTRAINT FK_datago_orders_id_order FOREIGN KEY (id_order) REFERENCES orders (id) ON UPDATE CASCADE ON DELETE CASCADE 
              ) ENGINE=InnoDB');

        $this->upgradeOK();
    }

    public function check_DataGoParameters(): bool
    {
        return $this->checkTableExists('datago_parameters');
    }

    /** Create datago_parameters table */
    public function upgrade_DataGoParameters(): void
    {
        sqlQuery('CREATE TABLE IF NOT EXISTS datago_parameters (
              name VARCHAR(100) NOT NULL PRIMARY KEY,
              id_parameter INT(10) UNSIGNED NOT NULL,
              CONSTRAINT FK_datago_parameters_id_parameter FOREIGN KEY (id_parameter) REFERENCES parameters (id) ON UPDATE CASCADE ON DELETE CASCADE 
              ) ENGINE=InnoDB');

        $this->upgradeOK();
    }
}
