using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace IRaCIS.Core.Infra.EFCore.Migrations
{
    /// <inheritdoc />
    public partial class svBack : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "ImageBackState",
                table: "SubjectVisit");

            migrationBuilder.CreateTable(
                name: "SubjectVisitImageBackRecord",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SubjectVisitId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ApplyUserRole = table.Column<int>(type: "int", nullable: false),
                    ImageBackState = table.Column<int>(type: "int", nullable: false, comment: "影像上传 回退"),
                    AuditTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SubjectVisitImageBackRecord", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SubjectVisitImageBackRecord_SubjectVisit_SubjectVisitId",
                        column: x => x.SubjectVisitId,
                        principalTable: "SubjectVisit",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_SubjectVisitImageBackRecord_User_CreateUserId",
                        column: x => x.CreateUserId,
                        principalTable: "User",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "受试者访视影像回退记录表");

            migrationBuilder.CreateIndex(
                name: "IX_SubjectVisitImageBackRecord_CreateUserId",
                table: "SubjectVisitImageBackRecord",
                column: "CreateUserId");

            migrationBuilder.CreateIndex(
                name: "IX_SubjectVisitImageBackRecord_SubjectVisitId",
                table: "SubjectVisitImageBackRecord",
                column: "SubjectVisitId");
        }

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

            migrationBuilder.AddColumn<int>(
                name: "ImageBackState",
                table: "SubjectVisit",
                type: "int",
                nullable: false,
                defaultValue: 0,
                comment: "影像上传 回退");
        }
    }
}
