using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace IRaCIS.Core.Infra.EFCore.Migrations
{
    /// <inheritdoc />
    public partial class Binding : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<Guid>(
                name: "MarkId",
                table: "ReadingNoneDicomMark",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "ReadingNoneDicomMarkBinding",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    VisitTaskId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    QuestionId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    RowId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    TableQuestionId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    NoneDicomMarkId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MarkId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ReadingNoneDicomMarkBinding", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ReadingNoneDicomMarkBinding_NoneDicomStudy_NoneDicomMarkId",
                        column: x => x.NoneDicomMarkId,
                        principalTable: "NoneDicomStudy",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ReadingNoneDicomMarkBinding_User_CreateUserId",
                        column: x => x.CreateUserId,
                        principalTable: "User",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "项目阅片 - 非Dicom标记绑定");

            migrationBuilder.CreateIndex(
                name: "IX_ReadingNoneDicomMarkBinding_CreateUserId",
                table: "ReadingNoneDicomMarkBinding",
                column: "CreateUserId");

            migrationBuilder.CreateIndex(
                name: "IX_ReadingNoneDicomMarkBinding_NoneDicomMarkId",
                table: "ReadingNoneDicomMarkBinding",
                column: "NoneDicomMarkId");
        }

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

            migrationBuilder.DropColumn(
                name: "MarkId",
                table: "ReadingNoneDicomMark");
        }
    }
}
