<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260203120000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add start and end dates to absences';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE absences ADD start_date DATE DEFAULT NULL');
        $this->addSql('ALTER TABLE absences ADD end_date DATE DEFAULT NULL');
        $this->addSql('UPDATE absences SET start_date = date, end_date = date');
        $this->addSql('ALTER TABLE absences ALTER COLUMN start_date SET NOT NULL');
        $this->addSql('ALTER TABLE absences ALTER COLUMN end_date SET NOT NULL');
        $this->addSql('ALTER TABLE absences DROP COLUMN date');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE absences ADD date DATE NOT NULL');
        $this->addSql('UPDATE absences SET date = start_date');
        $this->addSql('ALTER TABLE absences DROP COLUMN start_date');
        $this->addSql('ALTER TABLE absences DROP COLUMN end_date');
    }
}
