using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Aberwyn.Migrations
{
    public partial class AddBudgetDefinitions : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "BudgetItemDefinitionId",
                table: "BudgetItems",
                type: "int",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "BudgetCategoryDefinitionId",
                table: "BudgetCategories",
                type: "int",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "BudgetCategoryDefinition",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Color = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BudgetCategoryDefinition", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "BudgetItemDefinition",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DefaultCategory = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsExpense = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    IncludeInSummary = table.Column<bool>(type: "tinyint(1)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BudgetItemDefinition", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_BudgetItems_BudgetItemDefinitionId",
                table: "BudgetItems",
                column: "BudgetItemDefinitionId");

            migrationBuilder.CreateIndex(
                name: "IX_BudgetCategories_BudgetCategoryDefinitionId",
                table: "BudgetCategories",
                column: "BudgetCategoryDefinitionId");

            migrationBuilder.AddForeignKey(
                name: "FK_BudgetCategories_BudgetCategoryDefinition_BudgetCategoryDefi~",
                table: "BudgetCategories",
                column: "BudgetCategoryDefinitionId",
                principalTable: "BudgetCategoryDefinition",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_BudgetItems_BudgetItemDefinition_BudgetItemDefinitionId",
                table: "BudgetItems",
                column: "BudgetItemDefinitionId",
                principalTable: "BudgetItemDefinition",
                principalColumn: "Id");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_BudgetCategories_BudgetCategoryDefinition_BudgetCategoryDefi~",
                table: "BudgetCategories");

            migrationBuilder.DropForeignKey(
                name: "FK_BudgetItems_BudgetItemDefinition_BudgetItemDefinitionId",
                table: "BudgetItems");

            migrationBuilder.DropTable(
                name: "BudgetCategoryDefinition");

            migrationBuilder.DropTable(
                name: "BudgetItemDefinition");

            migrationBuilder.DropIndex(
                name: "IX_BudgetItems_BudgetItemDefinitionId",
                table: "BudgetItems");

            migrationBuilder.DropIndex(
                name: "IX_BudgetCategories_BudgetCategoryDefinitionId",
                table: "BudgetCategories");

            migrationBuilder.DropColumn(
                name: "BudgetItemDefinitionId",
                table: "BudgetItems");

            migrationBuilder.DropColumn(
                name: "BudgetCategoryDefinitionId",
                table: "BudgetCategories");
        }
    }
}
