using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace esuite.Database.SqlServer.Migrations
{
    /// <inheritdoc />
    public partial class addingactivityassignments : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "ActivityAssignments",
                schema: "Activity",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Guid = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Deleted = table.Column<bool>(type: "bit", nullable: false),
                    TaskId = table.Column<long>(type: "bigint", nullable: false),
                    Raci = table.Column<int>(type: "int", nullable: false),
                    RoleId = table.Column<long>(type: "bigint", nullable: true),
                    UserId = table.Column<long>(type: "bigint", nullable: true),
                    AllowNoVerdict = table.Column<bool>(type: "bit", nullable: false),
                    Bypassable = table.Column<bool>(type: "bit", nullable: false),
                    LastUpdated = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ActivityAssignments", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ActivityAssignments_ActivityTasks_TaskId",
                        column: x => x.TaskId,
                        principalSchema: "Activity",
                        principalTable: "ActivityTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ActivityAssignments_Roles_RoleId",
                        column: x => x.RoleId,
                        principalSchema: "Domain",
                        principalTable: "Roles",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_ActivityAssignments_Users_UserId",
                        column: x => x.UserId,
                        principalSchema: "UserManager",
                        principalTable: "Users",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_ActivityAssignments_Guid",
                schema: "Activity",
                table: "ActivityAssignments",
                column: "Guid",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ActivityAssignments_RoleId",
                schema: "Activity",
                table: "ActivityAssignments",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_ActivityAssignments_TaskId",
                schema: "Activity",
                table: "ActivityAssignments",
                column: "TaskId");

            migrationBuilder.CreateIndex(
                name: "IX_ActivityAssignments_UserId",
                schema: "Activity",
                table: "ActivityAssignments",
                column: "UserId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ActivityAssignments",
                schema: "Activity");
        }
    }
}
