<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class TaskInc69300 extends AbstractMigration
{
    public function up(): void
    {
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 1108385');
        if ($row['id']) {
            $builder = $this->getQueryBuilder();
            $builder->update('seguro.propostas_docusign')
                    ->set('fl_ativo', 'FALSE')
                    ->where(['id_proposta' => 1108385])
                    ->execute();
            $table = $this->table('seguro.propostas_docusign');
            $singleRow = [
                           'id_usuario_criacao' => 2068
                         , 'dt_criacao' => 'NOW()'
                         , 'id_proposta' => 1108385
                         , 'id_envelope' => NULL
                         , 'ds_status' => 'error'
                         , 'id_proposta_email_assinatura_documento' => 207976
                         , 'st_tipo_envio' => 'P'
            ];
            $table->insert($singleRow)
                  ->saveData();
        }
    }

    public function down(): void
    {
        $row = $this->fetchRow('SELECT id FROM seguro.propostas WHERE id = 1108385');
        if ($row['id']) {
            $delete = $this->getQueryBuilder();
            $delete->delete('seguro.propostas_docusign')
                   ->where(['id_usuario_criacao' => 2068, 'id_proposta' => 1108385, 'ds_status' => 'error', 'id_proposta_email_assinatura_documento' => 207976])
                   ->execute();
            $builder = $this->getQueryBuilder();
            $builder->update('seguro.propostas_docusign')
                    ->set('fl_ativo', 'TRUE')
                    ->where(['id_proposta' => 1108385, 'id_usuario_criacao' => 2068])
                    ->execute();
        }
    }
}