<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class Task2304131833 extends AbstractMigration
{
    public function up(): void
    {
        $row = $this->fetchRow('SELECT id_proposta FROM seguro.propostas_endosso WHERE id_proposta = 829841 and id_endosso = 667952');
        if ($row['id_proposta']) {
            $table = $this->table('seguro.propostas_parcelas');
            $singleRow = [
                           'id_usuario_criacao'    => 2068
                         , 'dt_criacao'            => 'NOW()'
                         , 'id_proposta'           => 829841
                         , 'nr_parcela'            => 2
                         , 'vl_total'              => 22980.12
                         , 'vl_segurado'           => 22980.12
                         , 'vl_subvencao_federal'  => 0.00
                         , 'vl_subvencao_estadual' => 0.00
                         , 'dt_vencimento'         => '2023-04-14'
                         , 'fl_pago'               => 'FALSE'
                         , 'id_endosso'            => 667952
            ];
            $table->insert($singleRow)
                  ->saveData();
        }
    }

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