<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class TaskSr70618 extends AbstractMigration
{
    public function up(): void
    {
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 1138483');
        if ($row['id']) {
            $this->execute("SELECT manutencao.atualizar_status (1138483,  8, 1138483, NULL, FALSE)");
        }
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 1138506');
        if ($row['id']) {
            $this->execute("SELECT manutencao.atualizar_status (1138506,  8, 1138506, NULL, FALSE)");
        }
    }

    public function down(): void
    {
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 1138483');
        if ($row['id']) {
            $this->execute("SELECT manutencao.atualizar_status (1138483, 62, 1089068, NULL, FALSE)");
            $builder = $this->getQueryBuilder();
            $builder->update('seguro.propostas_endosso')
                    ->set('fl_proposta_vigente', 'TRUE')
                    ->where(['id_endosso' => 865845, 'id_proposta' => 1089068])
                    ->execute();
            $builder = $this->getQueryBuilder();
            $builder->update('seguro.propostas_endosso')
                    ->set('fl_proposta_vigente', 'FALSE')
                    ->where(['id_endosso' => 865845, 'id_proposta' => 1138483])
                    ->execute();
        }
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 1138506');
        if ($row['id']) {
            $this->execute("SELECT manutencao.atualizar_status (1138506, 62, 1089433, NULL, FALSE)");
            $builder = $this->getQueryBuilder();
            $builder->update('seguro.propostas_endosso')
                    ->set('fl_proposta_vigente', 'TRUE')
                    ->where(['id_endosso' => 866147, 'id_proposta' => 1089433])
                    ->execute();
            $builder = $this->getQueryBuilder();
            $builder->update('seguro.propostas_endosso')
                    ->set('fl_proposta_vigente', 'FALSE')
                    ->where(['id_endosso' => 866147, 'id_proposta' => 1138506])
                    ->execute();
        }
    }
}
