using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace GiecChallenge.Migrations
{
    /// <inheritdoc />
    public partial class AddForms : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<string>(
                name: "Discriminator",
                table: "Products",
                type: "character varying(8)",
                maxLength: 8,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "text");

            migrationBuilder.CreateTable(
                name: "FormQuestions",
                columns: table => new
                {
                    id = table.Column<Guid>(type: "uuid", nullable: false),
                    Order = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FormQuestions", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "FormQuestionsAnswers",
                columns: table => new
                {
                    id = table.Column<Guid>(type: "uuid", nullable: false),
                    formQuestionid = table.Column<Guid>(type: "uuid", nullable: false),
                    order = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FormQuestionsAnswers", x => x.id);
                    table.ForeignKey(
                        name: "FK_FormQuestionsAnswers_FormQuestions_formQuestionid",
                        column: x => x.formQuestionid,
                        principalTable: "FormQuestions",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "FormQuestionsLanguages",
                columns: table => new
                {
                    id = table.Column<Guid>(type: "uuid", nullable: false),
                    questionid = table.Column<Guid>(type: "uuid", nullable: false),
                    languageid = table.Column<Guid>(type: "uuid", nullable: false),
                    text = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FormQuestionsLanguages", x => x.id);
                    table.ForeignKey(
                        name: "FK_FormQuestionsLanguages_FormQuestions_questionid",
                        column: x => x.questionid,
                        principalTable: "FormQuestions",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_FormQuestionsLanguages_Languages_languageid",
                        column: x => x.languageid,
                        principalTable: "Languages",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "FormQuestionsAnswersLanguages",
                columns: table => new
                {
                    id = table.Column<Guid>(type: "uuid", nullable: false),
                    answerid = table.Column<Guid>(type: "uuid", nullable: false),
                    languageid = table.Column<Guid>(type: "uuid", nullable: false),
                    text = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FormQuestionsAnswersLanguages", x => x.id);
                    table.ForeignKey(
                        name: "FK_FormQuestionsAnswersLanguages_FormQuestionsAnswers_answerid",
                        column: x => x.answerid,
                        principalTable: "FormQuestionsAnswers",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_FormQuestionsAnswersLanguages_Languages_languageid",
                        column: x => x.languageid,
                        principalTable: "Languages",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "FormQuestionsAnswersUsers",
                columns: table => new
                {
                    id = table.Column<Guid>(type: "uuid", nullable: false),
                    answerid = table.Column<Guid>(type: "uuid", nullable: false),
                    userid = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FormQuestionsAnswersUsers", x => x.id);
                    table.ForeignKey(
                        name: "FK_FormQuestionsAnswersUsers_FormQuestionsAnswers_answerid",
                        column: x => x.answerid,
                        principalTable: "FormQuestionsAnswers",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_FormQuestionsAnswersUsers_Users_userid",
                        column: x => x.userid,
                        principalTable: "Users",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_FormQuestionsAnswers_formQuestionid",
                table: "FormQuestionsAnswers",
                column: "formQuestionid");

            migrationBuilder.CreateIndex(
                name: "IX_FormQuestionsAnswersLanguages_answerid",
                table: "FormQuestionsAnswersLanguages",
                column: "answerid");

            migrationBuilder.CreateIndex(
                name: "IX_FormQuestionsAnswersLanguages_languageid",
                table: "FormQuestionsAnswersLanguages",
                column: "languageid");

            migrationBuilder.CreateIndex(
                name: "IX_FormQuestionsAnswersUsers_answerid",
                table: "FormQuestionsAnswersUsers",
                column: "answerid");

            migrationBuilder.CreateIndex(
                name: "IX_FormQuestionsAnswersUsers_userid",
                table: "FormQuestionsAnswersUsers",
                column: "userid");

            migrationBuilder.CreateIndex(
                name: "IX_FormQuestionsLanguages_languageid",
                table: "FormQuestionsLanguages",
                column: "languageid");

            migrationBuilder.CreateIndex(
                name: "IX_FormQuestionsLanguages_questionid",
                table: "FormQuestionsLanguages",
                column: "questionid");
        }

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

            migrationBuilder.DropTable(
                name: "FormQuestionsAnswersUsers");

            migrationBuilder.DropTable(
                name: "FormQuestionsLanguages");

            migrationBuilder.DropTable(
                name: "FormQuestionsAnswers");

            migrationBuilder.DropTable(
                name: "FormQuestions");

            migrationBuilder.AlterColumn<string>(
                name: "Discriminator",
                table: "Products",
                type: "text",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "character varying(8)",
                oldMaxLength: 8);
        }
    }
}
