<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260219193726 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create refresh_token table for JWT refresh-token rotation.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE refresh_token (id CHAR(36) NOT NULL, user_id CHAR(36) NOT NULL, token_hash VARCHAR(64) NOT NULL, expires_at DATETIME NOT NULL, revoked_at DATETIME DEFAULT NULL, created_at DATETIME NOT NULL, UNIQUE INDEX uniq_refresh_token_hash (token_hash), INDEX idx_refresh_token_user_id (user_id), INDEX idx_refresh_token_expires_at (expires_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('ALTER TABLE refresh_token ADD CONSTRAINT FK_65A8EFCBA76ED395 FOREIGN KEY (user_id) REFERENCES app_user (id) ON DELETE CASCADE');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE refresh_token DROP FOREIGN KEY FK_65A8EFCBA76ED395');
        $this->addSql('DROP TABLE refresh_token');
    }
}
