<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\Migrations\Person;

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

final class Version20250918095044 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add more details about presence in PersonIdentifier';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE chill_person_identifier_definition ADD presence VARCHAR(255) DEFAULT \'ON_EDIT\' NOT NULL');
        $this->addSql('UPDATE chill_person_identifier_definition SET presence = \'NOT_EDITABLE\' WHERE is_editable_by_users IS FALSE');
        $this->addSql('ALTER TABLE chill_person_identifier_definition DROP is_editable_by_users');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE chill_person_identifier_definition ADD is_editable_by_users BOOLEAN DEFAULT false NOT NULL');
        $this->addSql('UPDATE chill_person_identifier_definition SET is_editable_by_users = true WHERE presence <> \'NOT_EDITABLE\' ');
        $this->addSql('ALTER TABLE chill_person_identifier_definition DROP presence');
    }
}
