<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

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

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