<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20250422095126 extends AbstractMigration
{
    public function getDescription() : string
    {
        return 'Operations related to changing ManyToMany relationship "caissiers" to explicit relation entity "Caissier"';
    }

    public function up(Schema $schema) : void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE user_caissier DROP FOREIGN KEY FK_FF8E6FC2A76ED395');
        $this->addSql('ALTER TABLE user_caissier DROP FOREIGN KEY FK_FF8E6FC2BE3DB2B7');
        $this->addSql('ALTER TABLE user_caissier ADD id INT AUTO_INCREMENT NOT NULL, ADD last_transactions_export_datetime DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', DROP PRIMARY KEY, ADD PRIMARY KEY (id)');
        $this->addSql('ALTER TABLE user_caissier RENAME TO caissier');
        $this->addSql('ALTER TABLE caissier ADD CONSTRAINT FK_1F038BC2A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
        $this->addSql('ALTER TABLE caissier ADD CONSTRAINT FK_1F038BC2BE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id)');
    }

    public function down(Schema $schema) : void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE caissier DROP FOREIGN KEY FK_1F038BC2A76ED395');
        $this->addSql('ALTER TABLE caissier DROP FOREIGN KEY FK_1F038BC2BE3DB2B7');
        $this->addSql('ALTER TABLE caissier DROP PRIMARY KEY, ADD PRIMARY KEY (prestataire_id, user_id), DROP COLUMN id, DROP COLUMN last_transactions_export_datetime');
        $this->addSql('ALTER TABLE caissier RENAME TO user_caissier');
        $this->addSql('ALTER TABLE user_caissier ADD CONSTRAINT FK_FF8E6FC2A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
        $this->addSql('ALTER TABLE user_caissier ADD CONSTRAINT FK_FF8E6FC2BE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id)');
    }
}
