using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
{
    /// <inheritdoc />
    public partial class AddSelfScheduledExperimentSelectionWindowsAndInstructors : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<DateTime>(
                name: "SelectionEndsAt",
                table: "ExperimentProjects",
                type: "datetime(6)",
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "SelectionStartsAt",
                table: "ExperimentProjects",
                type: "datetime(6)",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "ExperimentSessionInstructors",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    ExperimentSessionId = table.Column<Guid>(type: "char(36)", nullable: false),
                    TeacherId = table.Column<Guid>(type: "char(36)", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ExperimentSessionInstructors", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ExperimentSessionInstructors_ExperimentSessions_ExperimentSe~",
                        column: x => x.ExperimentSessionId,
                        principalTable: "ExperimentSessions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ExperimentSessionInstructors_Teachers_TeacherId",
                        column: x => x.TeacherId,
                        principalTable: "Teachers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_ExperimentSessionInstructors_ExperimentSessionId_TeacherId",
                table: "ExperimentSessionInstructors",
                columns: new[] { "ExperimentSessionId", "TeacherId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ExperimentSessionInstructors_TeacherId",
                table: "ExperimentSessionInstructors",
                column: "TeacherId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ExperimentSessionInstructors");

            migrationBuilder.DropColumn(
                name: "SelectionEndsAt",
                table: "ExperimentProjects");

            migrationBuilder.DropColumn(
                name: "SelectionStartsAt",
                table: "ExperimentProjects");
        }
    }
}
