using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Apollinare.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddCustomFieldsSystem : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "WarehouseLocations",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "WarehouseArticles",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "WarehouseArticleCategories",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "VirtualDatasets",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "Utenti",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "TipiRisorsa",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "TipiPasto",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "TipiOspite",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "TipiMateriale",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "TipiEvento",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "StockValuations",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "StockValuationLayers",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "StockMovements",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "StockMovementLines",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "StockLevels",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "Risorse",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "ReportTemplates",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "ReportImages",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "ReportFonts",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "MovementReasons",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "ModuleSubscriptions",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "Location",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "InventoryCounts",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "InventoryCountLines",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "EventiDettaglioRisorse",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "EventiDettaglioPrelievo",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "EventiDettaglioOspiti",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "EventiDegustazioni",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "EventiAltriCosti",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "EventiAllegati",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "EventiAcconti",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "Eventi",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "Configurazioni",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "CodiciCategoria",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "Clienti",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "AutoCodes",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "Articoli",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "ArticleSerials",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "ArticleBatches",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "ArticleBarcodes",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "CustomFieldsJson",
                table: "AppModules",
                type: "TEXT",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "CustomFieldDefinitions",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    EntityName = table.Column<string>(type: "TEXT", nullable: false),
                    FieldName = table.Column<string>(type: "TEXT", nullable: false),
                    Label = table.Column<string>(type: "TEXT", nullable: false),
                    Type = table.Column<int>(type: "INTEGER", nullable: false),
                    IsRequired = table.Column<bool>(type: "INTEGER", nullable: false),
                    DefaultValue = table.Column<string>(type: "TEXT", nullable: true),
                    OptionsJson = table.Column<string>(type: "TEXT", nullable: true),
                    SortOrder = table.Column<int>(type: "INTEGER", nullable: false),
                    Description = table.Column<string>(type: "TEXT", nullable: true),
                    IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
                    ValidationRegex = table.Column<string>(type: "TEXT", nullable: true),
                    Placeholder = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    CustomFieldsJson = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CustomFieldDefinitions", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_CustomFieldDefinitions_EntityName",
                table: "CustomFieldDefinitions",
                column: "EntityName");

            migrationBuilder.CreateIndex(
                name: "IX_CustomFieldDefinitions_EntityName_FieldName",
                table: "CustomFieldDefinitions",
                columns: new[] { "EntityName", "FieldName" },
                unique: true);
        }

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

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "WarehouseLocations");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "WarehouseArticles");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "WarehouseArticleCategories");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "VirtualDatasets");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "Utenti");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "TipiRisorsa");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "TipiPasto");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "TipiOspite");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "TipiMateriale");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "TipiEvento");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "StockValuations");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "StockValuationLayers");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "StockMovements");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "StockMovementLines");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "StockLevels");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "Risorse");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "ReportTemplates");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "ReportImages");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "ReportFonts");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "MovementReasons");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "ModuleSubscriptions");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "Location");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "InventoryCounts");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "InventoryCountLines");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "EventiDettaglioRisorse");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "EventiDettaglioPrelievo");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "EventiDettaglioOspiti");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "EventiDegustazioni");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "EventiAltriCosti");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "EventiAllegati");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "EventiAcconti");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "Eventi");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "Configurazioni");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "CodiciCategoria");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "Clienti");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "AutoCodes");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "Articoli");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "ArticleSerials");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "ArticleBatches");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "ArticleBarcodes");

            migrationBuilder.DropColumn(
                name: "CustomFieldsJson",
                table: "AppModules");
        }
    }
}
