<?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 Version20211116101643 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('ALTER TABLE tchat DROP FOREIGN KEY FK_8EA99CA4E8EBF277');
        $this->addSql('CREATE TABLE tchat_conversation (id INT AUTO_INCREMENT NOT NULL, last_message_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_185132D6BA0E79C3 (last_message_id), INDEX last_message_id_index (last_message_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE tchat_message (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, conversation_id INT DEFAULT NULL, content LONGTEXT NOT NULL, INDEX IDX_F45F6AE9A76ED395 (user_id), INDEX IDX_F45F6AE99AC0396 (conversation_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE tchat_participant (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, conversation_id INT DEFAULT NULL, INDEX IDX_DA05CFDDA76ED395 (user_id), INDEX IDX_DA05CFDD9AC0396 (conversation_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('ALTER TABLE tchat_conversation ADD CONSTRAINT FK_185132D6BA0E79C3 FOREIGN KEY (last_message_id) REFERENCES tchat_message (id)');
        $this->addSql('ALTER TABLE tchat_message ADD CONSTRAINT FK_F45F6AE9A76ED395 FOREIGN KEY (user_id) REFERENCES symfony_demo_user (id)');
        $this->addSql('ALTER TABLE tchat_message ADD CONSTRAINT FK_F45F6AE99AC0396 FOREIGN KEY (conversation_id) REFERENCES tchat_conversation (id)');
        $this->addSql('ALTER TABLE tchat_participant ADD CONSTRAINT FK_DA05CFDDA76ED395 FOREIGN KEY (user_id) REFERENCES symfony_demo_user (id)');
        $this->addSql('ALTER TABLE tchat_participant ADD CONSTRAINT FK_DA05CFDD9AC0396 FOREIGN KEY (conversation_id) REFERENCES tchat_conversation (id)');
        $this->addSql('DROP TABLE pole');
        $this->addSql('DROP TABLE tchat');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_8FB094A1F85E0677 ON symfony_demo_user (username)');
        $this->addSql('ALTER TABLE user_filter CHANGE filtre filtre VARCHAR(255) DEFAULT NULL');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE tchat_message DROP FOREIGN KEY FK_F45F6AE99AC0396');
        $this->addSql('ALTER TABLE tchat_participant DROP FOREIGN KEY FK_DA05CFDD9AC0396');
        $this->addSql('ALTER TABLE tchat_conversation DROP FOREIGN KEY FK_185132D6BA0E79C3');
        $this->addSql('CREATE TABLE pole (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
        $this->addSql('CREATE TABLE tchat (id INT AUTO_INCREMENT NOT NULL, user_sender_id INT NOT NULL, user_receiver_id INT DEFAULT NULL, group_receiver_id INT DEFAULT NULL, message LONGTEXT CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, date_envoi DATETIME NOT NULL, date_read DATETIME DEFAULT NULL, INDEX IDX_8EA99CA4F6C43E79 (user_sender_id), INDEX IDX_8EA99CA464482423 (user_receiver_id), INDEX IDX_8EA99CA4E8EBF277 (group_receiver_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
        $this->addSql('ALTER TABLE tchat ADD CONSTRAINT FK_8EA99CA464482423 FOREIGN KEY (user_receiver_id) REFERENCES symfony_demo_user (id)');
        $this->addSql('ALTER TABLE tchat ADD CONSTRAINT FK_8EA99CA4E8EBF277 FOREIGN KEY (group_receiver_id) REFERENCES pole (id)');
        $this->addSql('ALTER TABLE tchat ADD CONSTRAINT FK_8EA99CA4F6C43E79 FOREIGN KEY (user_sender_id) REFERENCES symfony_demo_user (id)');
        $this->addSql('DROP TABLE tchat_conversation');
        $this->addSql('DROP TABLE tchat_message');
        $this->addSql('DROP TABLE tchat_participant');
        $this->addSql('DROP INDEX UNIQ_8FB094A1F85E0677 ON symfony_demo_user');
        $this->addSql('ALTER TABLE user_filter CHANGE filtre filtre TEXT CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`');
    }
}
