<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class Task2301111658 extends AbstractMigration
{
    public function up(): void
    {
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 813633');
        if ($row['id']) {
            $table = $this->table('seguro.propostas_parcelas');
            $singleRow = [
                           'id_usuario_criacao'    => 2068
                         , 'dt_criacao'            => 'NOW()'
                         , 'id_proposta'           => 789578
                         , 'nr_parcela'            => 2
                         , 'vl_total'              => 4462.05
                         , 'vl_segurado'           => 0.00
                         , 'vl_subvencao_federal'  => 4462.05
                         , 'vl_subvencao_estadual' => 0.00
                         , 'dt_vencimento'         => '2023-01-30'
                         , 'fl_pago'               => 'FALSE'
                         , 'id_endosso'            => 647372
            ];
            $table->insert($singleRow)
                  ->saveData();
        }

        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 813642');
        if ($row['id']) {
            $table = $this->table('seguro.propostas_parcelas');
            $singleRow = [
                           'id_usuario_criacao'    => 2068
                         , 'dt_criacao'            => 'NOW()'
                         , 'id_proposta'           => 795154
                         , 'nr_parcela'            => 4
                         , 'vl_total'              => 1990.22
                         , 'vl_segurado'           => 0.00
                         , 'vl_subvencao_federal'  => 1990.22
                         , 'vl_subvencao_estadual' => 0.00
                         , 'dt_vencimento'         => '2023-01-30'
                         , 'fl_pago'               => 'FALSE'
                         , 'id_endosso'            => 652288
            ];
            $table->insert($singleRow)
                  ->saveData();
        }

        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 813648');
        if ($row['id']) {
            $table = $this->table('seguro.propostas_parcelas');
            $singleRow = [
                           'id_usuario_criacao'    => 2068
                         , 'dt_criacao'            => 'NOW()'
                         , 'id_proposta'           => 795523
                         , 'nr_parcela'            => 2
                         , 'vl_total'              => 9492.47
                         , 'vl_segurado'           => 0.00
                         , 'vl_subvencao_federal'  => 9492.47
                         , 'vl_subvencao_estadual' => 0.00
                         , 'dt_vencimento'         => '2023-01-30'
                         , 'fl_pago'               => 'FALSE'
                         , 'id_endosso'            => 652635
            ];
            $table->insert($singleRow)
                  ->saveData();
        }

        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 814795');
        if ($row['id']) {
            $table = $this->table('seguro.propostas_parcelas');
            $singleRow = [
                           'id_usuario_criacao'    => 2068
                         , 'dt_criacao'            => 'NOW()'
                         , 'id_proposta'           => 797733
                         , 'nr_parcela'            => 4
                         , 'vl_total'              => 4641.53
                         , 'vl_segurado'           => 0.00
                         , 'vl_subvencao_federal'  => 4641.53
                         , 'vl_subvencao_estadual' => 0.00
                         , 'dt_vencimento'         => '2023-01-30'
                         , 'fl_pago'               => 'FALSE'
                         , 'id_endosso'            => 654632
            ];
            $table->insert($singleRow)
                  ->saveData();
        }
    }

    public function down(): void
    {
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 814795');
        if ($row['id']) {
            $delete = $this->getQueryBuilder();
            $delete->delete('seguro.propostas_parcelas')
               ->where([ 'id_proposta' => 797733
                       , 'nr_parcela'  => 4
                      ])
               ->execute();
        }

        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 813648');
        if ($row['id']) {
            $delete = $this->getQueryBuilder();
            $delete->delete('seguro.propostas_parcelas')
               ->where([ 'id_proposta' => 795523
                       , 'nr_parcela'  => 2
                      ])
               ->execute();
        }

        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 813642');
        if ($row['id']) {
            $delete = $this->getQueryBuilder();
            $delete->delete('seguro.propostas_parcelas')
               ->where([ 'id_proposta' => 795154
                       , 'nr_parcela'  => 4
                      ])
               ->execute();
        }

        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 813633');
        if ($row['id']) {
            $delete = $this->getQueryBuilder();
            $delete->delete('seguro.propostas_parcelas')
               ->where([ 'id_proposta' => 789578
                       , 'nr_parcela'  => 2
                      ])
               ->execute();
        }
    }
}
