<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260321200000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Replace isScanned with state and firstScannedAt on billet_order';
    }

    public function up(Schema $schema): void
    {
        $this->addSql("ALTER TABLE billet_order ADD COLUMN IF NOT EXISTS state VARCHAR(20) DEFAULT 'valid' NOT NULL");
        $this->addSql('ALTER TABLE billet_order ADD COLUMN IF NOT EXISTS first_scanned_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
        $this->addSql('ALTER TABLE billet_order DROP COLUMN IF EXISTS is_scanned');
        $this->addSql('ALTER TABLE billet_order DROP COLUMN IF EXISTS scanned_at');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE billet_order ADD COLUMN IF NOT EXISTS is_scanned BOOLEAN DEFAULT false NOT NULL');
        $this->addSql('ALTER TABLE billet_order ADD COLUMN IF NOT EXISTS scanned_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
        $this->addSql('ALTER TABLE billet_order DROP COLUMN IF EXISTS state');
        $this->addSql('ALTER TABLE billet_order DROP COLUMN IF EXISTS first_scanned_at');
    }
}
