using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class tblsWorkInit : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.EnsureSchema(
                name: "job");

            migrationBuilder.CreateTable(
                name: "Jobs",
                schema: "job",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    Name = table.Column<string>(type: "text", nullable: false),
                    IsUmbrella = table.Column<bool>(type: "boolean", nullable: true),
                    MinValueRelationships = table.Column<int>(type: "integer", nullable: true),
                    MaxValueRelationships = table.Column<int>(type: "integer", nullable: true),
                    TemplateNameMask = table.Column<string>(type: "text", nullable: true),
                    TnkId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Jobs", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Jobs_Tnks_TnkId",
                        column: x => x.TnkId,
                        principalTable: "Tnks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "Таблица видов работ");

            migrationBuilder.CreateTable(
                name: "JobDetails",
                schema: "job",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    UnitFilter = table.Column<string>(type: "text", nullable: false),
                    JobId = table.Column<Guid>(type: "uuid", nullable: false),
                    ShortDescription = table.Column<string>(type: "text", nullable: false),
                    FullDescription = table.Column<string>(type: "text", nullable: false),
                    Solution = table.Column<string>(type: "text", nullable: false),
                    Duration = table.Column<string>(type: "text", nullable: false),
                    ReferenceDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_JobDetails", x => x.Id);
                    table.ForeignKey(
                        name: "FK_JobDetails_Jobs_JobId",
                        column: x => x.JobId,
                        principalSchema: "job",
                        principalTable: "Jobs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "Таблица описания критериев выборки ЭК, описание полей в АСУ ЕСПП");

            migrationBuilder.CreateTable(
                name: "FieldFilters",
                schema: "job",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    JobDetailId = table.Column<Guid>(type: "uuid", nullable: false),
                    FieldId = table.Column<Guid>(type: "uuid", nullable: false),
                    ValueMask = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FieldFilters", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FieldFilters_Fields_FieldId",
                        column: x => x.FieldId,
                        principalSchema: "unit",
                        principalTable: "Fields",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_FieldFilters_JobDetails_JobDetailId",
                        column: x => x.JobDetailId,
                        principalSchema: "job",
                        principalTable: "JobDetails",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "Таблица описания критериев выборки аттрибутов ЭК");

            migrationBuilder.CreateIndex(
                name: "IX_FieldFilters_FieldId",
                schema: "job",
                table: "FieldFilters",
                column: "FieldId");

            migrationBuilder.CreateIndex(
                name: "IX_FieldFilters_JobDetailId",
                schema: "job",
                table: "FieldFilters",
                column: "JobDetailId");

            migrationBuilder.CreateIndex(
                name: "IX_JobDetails_JobId",
                schema: "job",
                table: "JobDetails",
                column: "JobId");

            migrationBuilder.CreateIndex(
                name: "IX_Jobs_TnkId",
                schema: "job",
                table: "Jobs",
                column: "TnkId");
        }

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

            migrationBuilder.DropTable(
                name: "JobDetails",
                schema: "job");

            migrationBuilder.DropTable(
                name: "Jobs",
                schema: "job");
        }
    }
}
