<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20260331082809 extends AbstractMigration
{
    public function getDescription(): string
    {
        return '';
    }

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE sign_document_event DROP CONSTRAINT fk_d494c99c33f7837');
        $this->addSql('ALTER TABLE sign_document_field DROP CONSTRAINT fk_6d120366c33f7837');
        $this->addSql('ALTER TABLE sign_document_field DROP CONSTRAINT fk_6d1203669588c067');
        $this->addSql('ALTER TABLE sign_document_field DROP CONSTRAINT fk_6d12036690409a66');
        $this->addSql('ALTER TABLE sign_document_signer DROP CONSTRAINT fk_2b38977fc33f7837');
        $this->addSql('DROP TABLE sign_document');
        $this->addSql('DROP TABLE sign_document_event');
        $this->addSql('DROP TABLE sign_document_field');
        $this->addSql('DROP TABLE sign_document_signer');
        $this->addSql('ALTER TABLE attestation ADD pdf_file_signed VARCHAR(500) DEFAULT NULL');
        $this->addSql('ALTER TABLE attestation ADD pdf_file_certificate VARCHAR(500) DEFAULT NULL');
        $this->addSql('ALTER TABLE attestation ADD submitter_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE attestation DROP envelope_id');
        $this->addSql('ALTER TABLE attestation RENAME COLUMN pdf_path TO pdf_file_unsigned');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE TABLE sign_document (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, document_id VARCHAR(64) NOT NULL, title VARCHAR(255) NOT NULL, dest_email VARCHAR(255) NOT NULL, dest_name VARCHAR(255) NOT NULL, file_name VARCHAR(255) DEFAULT NULL, state VARCHAR(20) NOT NULL, hmac VARCHAR(128) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, sent_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, signed_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, refused_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, refused_reason TEXT DEFAULT NULL, path_pdf_unsigned VARCHAR(500) DEFAULT NULL, path_pdf_signed VARCHAR(500) DEFAULT NULL, path_pdf_signed_certificate VARCHAR(500) DEFAULT NULL, file_hmac VARCHAR(128) DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY (id))');
        $this->addSql('CREATE UNIQUE INDEX uniq_1bd06c91c33f7837 ON sign_document (document_id)');
        $this->addSql('CREATE TABLE sign_document_event (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, type VARCHAR(30) NOT NULL, detail TEXT DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, document_id INT NOT NULL, PRIMARY KEY (id))');
        $this->addSql('CREATE INDEX idx_d494c99c33f7837 ON sign_document_event (document_id)');
        $this->addSql('CREATE TABLE sign_document_field (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, type VARCHAR(30) NOT NULL, label VARCHAR(255) NOT NULL, page INT NOT NULL, position_x DOUBLE PRECISION NOT NULL, position_y DOUBLE PRECISION NOT NULL, width DOUBLE PRECISION NOT NULL, height DOUBLE PRECISION NOT NULL, "position" INT NOT NULL, value TEXT DEFAULT NULL, filled_value TEXT DEFAULT NULL, filled_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, required BOOLEAN NOT NULL, document_id INT NOT NULL, signer_id INT DEFAULT NULL, filled_by_id INT DEFAULT NULL, PRIMARY KEY (id))');
        $this->addSql('CREATE INDEX idx_6d120366c33f7837 ON sign_document_field (document_id)');
        $this->addSql('CREATE INDEX idx_6d1203669588c067 ON sign_document_field (signer_id)');
        $this->addSql('CREATE INDEX idx_6d12036690409a66 ON sign_document_field (filled_by_id)');
        $this->addSql('CREATE TABLE sign_document_signer (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, email VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, signing_order INT NOT NULL, state VARCHAR(20) NOT NULL, signed_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, refused_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, refused_reason TEXT DEFAULT NULL, token VARCHAR(64) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, document_id INT NOT NULL, PRIMARY KEY (id))');
        $this->addSql('CREATE UNIQUE INDEX uniq_2b38977f5f37a13b ON sign_document_signer (token)');
        $this->addSql('CREATE INDEX idx_2b38977fc33f7837 ON sign_document_signer (document_id)');
        $this->addSql('ALTER TABLE sign_document_event ADD CONSTRAINT fk_d494c99c33f7837 FOREIGN KEY (document_id) REFERENCES sign_document (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE sign_document_field ADD CONSTRAINT fk_6d120366c33f7837 FOREIGN KEY (document_id) REFERENCES sign_document (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE sign_document_field ADD CONSTRAINT fk_6d1203669588c067 FOREIGN KEY (signer_id) REFERENCES sign_document_signer (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE sign_document_field ADD CONSTRAINT fk_6d12036690409a66 FOREIGN KEY (filled_by_id) REFERENCES sign_document_signer (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE sign_document_signer ADD CONSTRAINT fk_2b38977fc33f7837 FOREIGN KEY (document_id) REFERENCES sign_document (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE attestation ADD pdf_path VARCHAR(500) DEFAULT NULL');
        $this->addSql('ALTER TABLE attestation ADD envelope_id VARCHAR(100) DEFAULT NULL');
        $this->addSql('ALTER TABLE attestation DROP pdf_file_unsigned');
        $this->addSql('ALTER TABLE attestation DROP pdf_file_signed');
        $this->addSql('ALTER TABLE attestation DROP pdf_file_certificate');
        $this->addSql('ALTER TABLE attestation DROP submitter_id');
    }
}
