<?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 Version20260219165514 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 app_user (id CHAR(36) NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, UNIQUE INDEX uniq_app_user_email (email), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE dart_throw (id CHAR(36) NOT NULL, dart_index INT NOT NULL, segment INT DEFAULT NULL, is_bull TINYINT NOT NULL, multiplier INT DEFAULT NULL, bull_value INT DEFAULT NULL, scored_points INT NOT NULL, created_at DATETIME NOT NULL, game_id CHAR(36) NOT NULL, turn_id CHAR(36) NOT NULL, player_id CHAR(36) NOT NULL, INDEX IDX_F2A53746E48FD905 (game_id), INDEX IDX_F2A537461F4F9889 (turn_id), INDEX IDX_F2A5374699E6F5DF (player_id), INDEX idx_throw_game_created_at (game_id, created_at), UNIQUE INDEX uniq_throw_dart_index_per_turn (turn_id, dart_index), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE `game` (id CHAR(36) NOT NULL, status VARCHAR(20) NOT NULL, started_at DATETIME DEFAULT NULL, finished_at DATETIME DEFAULT NULL, current_player_index INT NOT NULL, current_turn_number INT NOT NULL, current_dart_in_turn INT NOT NULL, in_rule VARCHAR(10) NOT NULL, out_rule VARCHAR(10) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, mode_id CHAR(36) NOT NULL, owner_id CHAR(36) NOT NULL, INDEX IDX_232B318C77E5854A (mode_id), INDEX IDX_232B318C7E3C61F9 (owner_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE game_event_log (id CHAR(36) NOT NULL, type VARCHAR(40) NOT NULL, payload JSON NOT NULL, created_at DATETIME NOT NULL, game_id CHAR(36) NOT NULL, INDEX IDX_4C566C14E48FD905 (game_id), INDEX idx_event_log_game_created_at (game_id, created_at), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE game_mode (id CHAR(36) NOT NULL, key_name VARCHAR(50) NOT NULL, name VARCHAR(50) NOT NULL, type VARCHAR(10) NOT NULL, start_score INT NOT NULL, rules JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, UNIQUE INDEX uniq_game_mode_key (key_name), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE game_player (id CHAR(36) NOT NULL, name VARCHAR(60) NOT NULL, position INT NOT NULL, current_score INT NOT NULL, is_winner TINYINT NOT NULL, has_checked_in TINYINT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, game_id CHAR(36) NOT NULL, INDEX IDX_E52CD7ADE48FD905 (game_id), UNIQUE INDEX uniq_game_player_position (game_id, position), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE turn (id CHAR(36) NOT NULL, turn_number INT NOT NULL, player_turn_index INT DEFAULT NULL, start_score INT NOT NULL, end_score INT DEFAULT NULL, total_scored INT NOT NULL, is_bust TINYINT NOT NULL, started_at DATETIME NOT NULL, ended_at DATETIME DEFAULT NULL, game_id CHAR(36) NOT NULL, player_id CHAR(36) NOT NULL, INDEX IDX_20201547E48FD905 (game_id), INDEX IDX_2020154799E6F5DF (player_id), UNIQUE INDEX uniq_turn_number_per_game (game_id, turn_number), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('ALTER TABLE dart_throw ADD CONSTRAINT FK_F2A53746E48FD905 FOREIGN KEY (game_id) REFERENCES `game` (id)');
        $this->addSql('ALTER TABLE dart_throw ADD CONSTRAINT FK_F2A537461F4F9889 FOREIGN KEY (turn_id) REFERENCES turn (id)');
        $this->addSql('ALTER TABLE dart_throw ADD CONSTRAINT FK_F2A5374699E6F5DF FOREIGN KEY (player_id) REFERENCES game_player (id)');
        $this->addSql('ALTER TABLE `game` ADD CONSTRAINT FK_232B318C77E5854A FOREIGN KEY (mode_id) REFERENCES game_mode (id)');
        $this->addSql('ALTER TABLE `game` ADD CONSTRAINT FK_232B318C7E3C61F9 FOREIGN KEY (owner_id) REFERENCES app_user (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE game_event_log ADD CONSTRAINT FK_4C566C14E48FD905 FOREIGN KEY (game_id) REFERENCES `game` (id)');
        $this->addSql('ALTER TABLE game_player ADD CONSTRAINT FK_E52CD7ADE48FD905 FOREIGN KEY (game_id) REFERENCES `game` (id)');
        $this->addSql('ALTER TABLE turn ADD CONSTRAINT FK_20201547E48FD905 FOREIGN KEY (game_id) REFERENCES `game` (id)');
        $this->addSql('ALTER TABLE turn ADD CONSTRAINT FK_2020154799E6F5DF FOREIGN KEY (player_id) REFERENCES game_player (id)');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE dart_throw DROP FOREIGN KEY FK_F2A53746E48FD905');
        $this->addSql('ALTER TABLE dart_throw DROP FOREIGN KEY FK_F2A537461F4F9889');
        $this->addSql('ALTER TABLE dart_throw DROP FOREIGN KEY FK_F2A5374699E6F5DF');
        $this->addSql('ALTER TABLE `game` DROP FOREIGN KEY FK_232B318C77E5854A');
        $this->addSql('ALTER TABLE `game` DROP FOREIGN KEY FK_232B318C7E3C61F9');
        $this->addSql('ALTER TABLE game_event_log DROP FOREIGN KEY FK_4C566C14E48FD905');
        $this->addSql('ALTER TABLE game_player DROP FOREIGN KEY FK_E52CD7ADE48FD905');
        $this->addSql('ALTER TABLE turn DROP FOREIGN KEY FK_20201547E48FD905');
        $this->addSql('ALTER TABLE turn DROP FOREIGN KEY FK_2020154799E6F5DF');
        $this->addSql('DROP TABLE app_user');
        $this->addSql('DROP TABLE dart_throw');
        $this->addSql('DROP TABLE `game`');
        $this->addSql('DROP TABLE game_event_log');
        $this->addSql('DROP TABLE game_mode');
        $this->addSql('DROP TABLE game_player');
        $this->addSql('DROP TABLE turn');
    }
}
