<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class Task2009241310 extends AbstractMigration
{
    public function up(): void
    {
        $this->execute(<<<SQL
INSERT INTO sistema.acao (ds_label, ds_module, ds_controller, ds_action, ds_param, id_parent, ds_image, ds_descricao, fl_tipo, dt_criacao, id_usuario_criacao, id) VALUES ('Cooperativas', 'sistema', 'cooperativa', 'index', '', 4, '', 'Cadastro de cooperativas.', 'M', '2020-09-29 14:27:15', 3379, nextval('sistema.acao_id_seq'::regclass));
SQL
        );

        $queryParent = $this->query("SELECT id FROM sistema.acao WHERE ds_label = 'Cooperativas' AND ds_module = 'sistema' AND ds_controller = 'cooperativa'");
        $rows = $queryParent->fetchAll();
        $idParent = $rows[0]['id'];

        $this->execute(<<<SQL
INSERT INTO sistema.acao (ds_label, ds_module, ds_controller, ds_action, ds_param, id_parent, ds_image, nr_ordem, fl_tipo, dt_criacao, id_usuario_criacao, id) VALUES ('Editar', 'sistema', 'cooperativa', 'form', 'id', $idParent, 'edit.png', '0', 'L', '2020-09-29 14:27:15', 3379, nextval('sistema.acao_id_seq'::regclass));
INSERT INTO sistema.acao (ds_label, ds_module, ds_controller, ds_action, ds_param, id_parent, ds_image, nr_ordem, fl_tipo, dt_criacao, id_usuario_criacao, id) VALUES ('Ativar/Desativar', 'sistema', 'cooperativa', 'active', 'id', $idParent, 'active.png', '1', 'L', '2020-09-29 14:27:15', 3379, nextval('sistema.acao_id_seq'::regclass));
INSERT INTO sistema.acao (ds_label, ds_module, ds_controller, ds_action, ds_param, id_parent, ds_image, nr_ordem, fl_tipo, dt_criacao, id_usuario_criacao, id) VALUES ('Deletar', 'sistema', 'cooperativa', 'delete', 'id', $idParent, 'delete.png', '2', 'L', '2020-09-29 14:27:15', 3379, nextval('sistema.acao_id_seq'::regclass));
SQL
        );
    }

    public function down(): void
    {
        $this->execute(<<<SQL
delete from sistema.acao where ds_label = 'Editar' and ds_module = 'sistema' and ds_controller = 'cooperativa';
delete from sistema.acao where ds_label = 'Ativar/Desativar' and ds_module = 'sistema' and ds_controller = 'cooperativa';
delete from sistema.acao where ds_label = 'Deletar' and ds_module = 'sistema' and ds_controller = 'cooperativa';
delete from sistema.acao where ds_label = 'Cooperativas' and ds_module = 'sistema' and ds_controller = 'cooperativa';
SQL
        );
    }
}
