<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
 * Absence management: add HR fields to the user table.
 *
 * Columns are created with DEFAULTs so the migration applies cleanly on an
 * already-populated user table (production).
 */
final class Version20260521123523 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add HR / absence fields to user';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE "user" ADD is_employee BOOLEAN NOT NULL DEFAULT false');
        $this->addSql('ALTER TABLE "user" ADD hire_date DATE DEFAULT NULL');
        $this->addSql('ALTER TABLE "user" ADD end_date DATE DEFAULT NULL');
        $this->addSql('ALTER TABLE "user" ADD contract_type VARCHAR(16) DEFAULT NULL');
        $this->addSql('ALTER TABLE "user" ADD work_time_ratio DOUBLE PRECISION NOT NULL DEFAULT 1.0');
        $this->addSql('ALTER TABLE "user" ADD annual_leave_days DOUBLE PRECISION NOT NULL DEFAULT 25.0');
        $this->addSql("ALTER TABLE \"user\" ADD reference_period_start VARCHAR(5) NOT NULL DEFAULT '06-01'");
        $this->addSql('ALTER TABLE "user" ADD initial_leave_balance DOUBLE PRECISION NOT NULL DEFAULT 0');
        $this->addSql('ALTER TABLE "user" ADD family_situation VARCHAR(16) DEFAULT NULL');
        $this->addSql('ALTER TABLE "user" ADD nb_children INT NOT NULL DEFAULT 0');

        // Defaults were only needed to backfill existing rows; the ORM mapping
        // carries no DB default, so drop them to keep the schema in sync.
        $this->addSql('ALTER TABLE "user" ALTER is_employee DROP DEFAULT');
        $this->addSql('ALTER TABLE "user" ALTER work_time_ratio DROP DEFAULT');
        $this->addSql('ALTER TABLE "user" ALTER annual_leave_days DROP DEFAULT');
        $this->addSql('ALTER TABLE "user" ALTER reference_period_start DROP DEFAULT');
        $this->addSql('ALTER TABLE "user" ALTER initial_leave_balance DROP DEFAULT');
        $this->addSql('ALTER TABLE "user" ALTER nb_children DROP DEFAULT');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE "user" DROP is_employee');
        $this->addSql('ALTER TABLE "user" DROP hire_date');
        $this->addSql('ALTER TABLE "user" DROP end_date');
        $this->addSql('ALTER TABLE "user" DROP contract_type');
        $this->addSql('ALTER TABLE "user" DROP work_time_ratio');
        $this->addSql('ALTER TABLE "user" DROP annual_leave_days');
        $this->addSql('ALTER TABLE "user" DROP reference_period_start');
        $this->addSql('ALTER TABLE "user" DROP initial_leave_balance');
        $this->addSql('ALTER TABLE "user" DROP family_situation');
        $this->addSql('ALTER TABLE "user" DROP nb_children');
    }
}
