<?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 Version20260310211017 extends AbstractMigration
{
    public function getDescription(): string
    {
        return '';
    }

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE TABLE time_entry (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, title VARCHAR(255) DEFAULT NULL, description TEXT DEFAULT NULL, started_at TIMESTAMP(0) WITH TIME ZONE NOT NULL, stopped_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, user_id INT NOT NULL, project_id INT DEFAULT NULL, task_id INT DEFAULT NULL, PRIMARY KEY (id))');
        $this->addSql('CREATE INDEX IDX_6E537C0CA76ED395 ON time_entry (user_id)');
        $this->addSql('CREATE INDEX IDX_6E537C0C166D1F9C ON time_entry (project_id)');
        $this->addSql('CREATE INDEX IDX_6E537C0C8DB60186 ON time_entry (task_id)');
        $this->addSql('CREATE UNIQUE INDEX uniq_active_timer ON time_entry (user_id) WHERE (stopped_at IS NULL)');
        $this->addSql('CREATE TABLE time_entry_task_type (time_entry_id INT NOT NULL, task_type_id INT NOT NULL, PRIMARY KEY (time_entry_id, task_type_id))');
        $this->addSql('CREATE INDEX IDX_BE7A719D1EB30A8E ON time_entry_task_type (time_entry_id)');
        $this->addSql('CREATE INDEX IDX_BE7A719DDAADA679 ON time_entry_task_type (task_type_id)');
        $this->addSql('ALTER TABLE time_entry ADD CONSTRAINT FK_6E537C0CA76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE');
        $this->addSql('ALTER TABLE time_entry ADD CONSTRAINT FK_6E537C0C166D1F9C FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE SET NULL NOT DEFERRABLE');
        $this->addSql('ALTER TABLE time_entry ADD CONSTRAINT FK_6E537C0C8DB60186 FOREIGN KEY (task_id) REFERENCES task (id) ON DELETE SET NULL NOT DEFERRABLE');
        $this->addSql('ALTER TABLE time_entry_task_type ADD CONSTRAINT FK_BE7A719D1EB30A8E FOREIGN KEY (time_entry_id) REFERENCES time_entry (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE time_entry_task_type ADD CONSTRAINT FK_BE7A719DDAADA679 FOREIGN KEY (task_type_id) REFERENCES task_type (id) ON DELETE CASCADE');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE time_entry DROP CONSTRAINT FK_6E537C0CA76ED395');
        $this->addSql('ALTER TABLE time_entry DROP CONSTRAINT FK_6E537C0C166D1F9C');
        $this->addSql('ALTER TABLE time_entry DROP CONSTRAINT FK_6E537C0C8DB60186');
        $this->addSql('ALTER TABLE time_entry_task_type DROP CONSTRAINT FK_BE7A719D1EB30A8E');
        $this->addSql('ALTER TABLE time_entry_task_type DROP CONSTRAINT FK_BE7A719DDAADA679');
        $this->addSql('DROP TABLE time_entry');
        $this->addSql('DROP TABLE time_entry_task_type');
    }
}
