<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260416100000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add work_days_hours JSON on employee_contract_periods (schedule for non-standard contracts) + seed Ewa and Nadia';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE employee_contract_periods ADD work_days_hours JSON DEFAULT NULL');

        // Seed the two known 4h employees currently in production.
        // Ewa DALEMBA: Lundi 2h + Jeudi 2h
        // Nadia GARRAUD: Mardi 2h + Vendredi 2h
        // Filter on last_name + first_name (not ids) to stay safe across environments,
        // and only on periods without an already-set schedule to remain idempotent.
        $this->addSql(
            "UPDATE employee_contract_periods ecp SET work_days_hours = '{\"1\":120,\"4\":120}' "
            .'FROM employees e '
            .'WHERE ecp.employee_id = e.id '
            ."AND e.last_name = 'DALEMBA' AND e.first_name = 'Ewa' "
            .'AND ecp.end_date IS NULL AND ecp.work_days_hours IS NULL'
        );
        $this->addSql(
            "UPDATE employee_contract_periods ecp SET work_days_hours = '{\"2\":120,\"5\":120}' "
            .'FROM employees e '
            .'WHERE ecp.employee_id = e.id '
            ."AND e.last_name = 'GARRAUD' AND e.first_name = 'Nadia' "
            .'AND ecp.end_date IS NULL AND ecp.work_days_hours IS NULL'
        );
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE employee_contract_periods DROP work_days_hours');
    }
}
