using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace IRaCIS.Core.Infra.EFCore.Migrations
{
    /// <inheritdoc />
    public partial class auditRecord : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AuditRecord",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CompanyName = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: false),
                    AuditContent = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: false),
                    AuditTime = table.Column<DateOnly>(type: "date", nullable: false, comment: "稽查日期"),
                    BeginTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    EndTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    AuditState = table.Column<int>(type: "int", nullable: false, comment: "稽查状态"),
                    AuditType = table.Column<int>(type: "int", nullable: false, comment: "稽查形式"),
                    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_AuditRecord", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AuditRecord_User_CreateUserId",
                        column: x => x.CreateUserId,
                        principalTable: "User",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AuditRecordIdentityUser",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    IdentityUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    AuditRecordId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AuditRecordIdentityUser", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AuditRecordIdentityUser_AuditRecord_AuditRecordId",
                        column: x => x.AuditRecordId,
                        principalTable: "AuditRecord",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AuditRecordIdentityUser_IdentityUser_IdentityUserId",
                        column: x => x.IdentityUserId,
                        principalTable: "IdentityUser",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AuditRecordIdentityUser_User_CreateUserId",
                        column: x => x.CreateUserId,
                        principalTable: "User",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AuditRecordPermission",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    AuditRecordId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    AuditDocumentId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AuditRecordPermission", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AuditRecordPermission_AuditDocument_AuditDocumentId",
                        column: x => x.AuditDocumentId,
                        principalTable: "AuditDocument",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AuditRecordPermission_AuditRecord_AuditRecordId",
                        column: x => x.AuditRecordId,
                        principalTable: "AuditRecord",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AuditRecordPermission_User_CreateUserId",
                        column: x => x.CreateUserId,
                        principalTable: "User",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AuditRecord_CreateUserId",
                table: "AuditRecord",
                column: "CreateUserId");

            migrationBuilder.CreateIndex(
                name: "IX_AuditRecordIdentityUser_AuditRecordId",
                table: "AuditRecordIdentityUser",
                column: "AuditRecordId");

            migrationBuilder.CreateIndex(
                name: "IX_AuditRecordIdentityUser_CreateUserId",
                table: "AuditRecordIdentityUser",
                column: "CreateUserId");

            migrationBuilder.CreateIndex(
                name: "IX_AuditRecordIdentityUser_IdentityUserId",
                table: "AuditRecordIdentityUser",
                column: "IdentityUserId");

            migrationBuilder.CreateIndex(
                name: "IX_AuditRecordPermission_AuditDocumentId",
                table: "AuditRecordPermission",
                column: "AuditDocumentId");

            migrationBuilder.CreateIndex(
                name: "IX_AuditRecordPermission_AuditRecordId",
                table: "AuditRecordPermission",
                column: "AuditRecordId");

            migrationBuilder.CreateIndex(
                name: "IX_AuditRecordPermission_CreateUserId",
                table: "AuditRecordPermission",
                column: "CreateUserId");
        }

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

            migrationBuilder.DropTable(
                name: "AuditRecordPermission");

            migrationBuilder.DropTable(
                name: "AuditRecord");
        }
    }
}
