<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class TaskInc46023 extends AbstractMigration
{
    public function up(): void
    {
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 934598');
        if ($row['id']) {
            $this->execute("CREATE TABLE seguro.bloqueio_download_apolice (
                                id_proposta     INTEGER     NOT NULL,
                                CONSTRAINT pk_bloqueio_download_apolice PRIMARY KEY (id_proposta),
                                CONSTRAINT fk_bloqueio_download_apolice FOREIGN KEY (id_proposta) REFERENCES seguro.propostas(id)
                            )
                            INHERITS (public.campos_default)
                            WITH ( OIDS=FALSE )
                          ");

            $this->execute("SELECT manutencao.atualizar_status (925571, 62, 925571, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (925175, 62, 925175, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (926439, 62, 926439, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (926151, 62, 926151, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (926362, 62, 926362, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (925744, 62, 925744, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (926689, 62, 926689, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (925828, 62, 925828, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (925846, 62, 925846, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927454, 62, 927454, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927128, 62, 927128, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (926840, 62, 926840, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927326, 62, 927326, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927348, 62, 927348, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (928577, 62, 928577, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927716, 62, 927716, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (928110, 62, 928110, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927591, 62, 927591, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (925559, 62, 925559, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (928193, 62, 928193, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (934598, 62, 934598, NULL, FALSE)");
    
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801541 WHERE id = 925571");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801494 WHERE id = 925175");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801543 WHERE id = 926439");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801417 WHERE id = 926151");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801488 WHERE id = 926362");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801526 WHERE id = 925744");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801474 WHERE id = 926689");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801424 WHERE id = 925828");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801509 WHERE id = 925846");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801502 WHERE id = 927454");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801496 WHERE id = 927128");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801540 WHERE id = 926840");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801455 WHERE id = 927326");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801528 WHERE id = 927348");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801447 WHERE id = 928577");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801508 WHERE id = 927716");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801542 WHERE id = 928110");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801466 WHERE id = 927591");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801476 WHERE id = 925559");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801492 WHERE id = 928193");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801479 WHERE id = 934598");
        }        
    }

    public function down(): void
    {
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 934598');
        if ($row['id']) {
            $this->execute("SELECT manutencao.atualizar_status (925571, 8, 925571, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (925175, 8, 925175, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (926439, 8, 926439, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (926151, 8, 926151, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (926362, 8, 926362, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (925744, 8, 925744, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (926689, 8, 926689, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (925828, 8, 925828, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (925846, 8, 925846, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927454, 8, 927454, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927128, 8, 927128, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (926840, 8, 926840, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927326, 8, 927326, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927348, 8, 927348, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (928577, 8, 928577, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927716, 8, 927716, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (928110, 8, 928110, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (927591, 8, 927591, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (925559, 8, 925559, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (928193, 8, 928193, NULL, FALSE)");
            $this->execute("SELECT manutencao.atualizar_status (934598, 8, 934598, NULL, FALSE)");

            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801415 WHERE id = 925571");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801408 WHERE id = 925175");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801430 WHERE id = 926439");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801423 WHERE id = 926151");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801429 WHERE id = 926362");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801418 WHERE id = 925744");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801436 WHERE id = 926689");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801420 WHERE id = 925828");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801422 WHERE id = 925846");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801457 WHERE id = 927454");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801444 WHERE id = 927128");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801440 WHERE id = 926840");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801449 WHERE id = 927326");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801451 WHERE id = 927348");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801472 WHERE id = 928577");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801460 WHERE id = 927716");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801463 WHERE id = 928110");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801459 WHERE id = 927591");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801413 WHERE id = 925559");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801465 WHERE id = 928193");
            $this->execute("UPDATE seguro.propostas SET ds_identificador_seguradora = 9801518 WHERE id = 934598");

            $this->table('seguro.bloqueio_download_apolice')
                 ->drop()
                 ->save();
        }
    }
}