using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional

namespace Marco.Pms.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class Added_New_Parameters_In_Tenant_Table : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.UpdateData(
                table: "Tenants",
                keyColumn: "Name",
                keyValue: null,
                column: "Name",
                value: "");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Tenants",
                type: "longtext",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "longtext",
                oldNullable: true)
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.UpdateData(
                table: "Tenants",
                keyColumn: "ContactNumber",
                keyValue: null,
                column: "ContactNumber",
                value: "");

            migrationBuilder.AlterColumn<string>(
                name: "ContactNumber",
                table: "Tenants",
                type: "longtext",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "longtext",
                oldNullable: true)
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.UpdateData(
                table: "Tenants",
                keyColumn: "ContactName",
                keyValue: null,
                column: "ContactName",
                value: "");

            migrationBuilder.AlterColumn<string>(
                name: "ContactName",
                table: "Tenants",
                type: "longtext",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "longtext",
                oldNullable: true)
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "BillingAddress",
                table: "Tenants",
                type: "longtext",
                nullable: false)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<Guid>(
                name: "CreatedById",
                table: "Tenants",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<string>(
                name: "Email",
                table: "Tenants",
                type: "longtext",
                nullable: false)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<bool>(
                name: "IsSuperTenant",
                table: "Tenants",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<string>(
                name: "Reference",
                table: "Tenants",
                type: "longtext",
                nullable: false)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "TaxId",
                table: "Tenants",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<Guid>(
                name: "TenantStatusId",
                table: "Tenants",
                type: "char(36)",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<string>(
                name: "logoImage",
                table: "Tenants",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "TenantStatus",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    Name = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TenantStatus", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.InsertData(
                table: "Modules",
                columns: new[] { "Id", "Description", "Key", "Name" },
                values: new object[] { new Guid("f482a079-4dec-4f2d-9867-6baf2a4f23d9"), "Tenant Module", "504ec132-e6a9-422f-8f85-050602cfce05", "Tenant" });

            migrationBuilder.InsertData(
                table: "TenantStatus",
                columns: new[] { "Id", "Name" },
                values: new object[,]
                {
                    { new Guid("35d7840a-164a-448b-95e6-efb2ec84a751"), "Suspended" },
                    { new Guid("62b05792-5115-4f99-8ff5-e8374859b191"), "Active" },
                    { new Guid("c0b5def8-087e-4235-b3a4-8e2f0ed91b94"), "In Active" }
                });

            migrationBuilder.UpdateData(
                table: "Tenants",
                keyColumn: "Id",
                keyValue: new Guid("b3466e83-7e11-464c-b93a-daf047838b26"),
                columns: new[] { "BillingAddress", "CreatedById", "Email", "IsSuperTenant", "Reference", "TaxId", "TenantStatusId", "logoImage" },
                values: new object[] { "2nd Floor, Fullora Building, Tejas CHS, behind Kothrud Stand, Tejas Society, Dahanukar Colony, Kothrud, Pune, Maharashtra 411038", null, "admin@marcoaiot.com", true, "Root Tenant", null, new Guid("62b05792-5115-4f99-8ff5-e8374859b191"), "data:image/jpeg;base64,[encoded data, 213816 characters]" });

            migrationBuilder.InsertData(
                table: "Features",
                columns: new[] { "Id", "Description", "IsActive", "ModuleId", "Name" },
                values: new object[] { new Guid("2f3509b7-160d-410a-b9b6-daadd96c986d"), "Managing all tenant related rights", true, new Guid("f482a079-4dec-4f2d-9867-6baf2a4f23d9"), "Tenant Management" });

            migrationBuilder.InsertData(
                table: "FeaturePermissions",
                columns: new[] { "Id", "Description", "FeatureId", "IsEnabled", "Name" },
                values: new object[,]
                {
                    { new Guid("00e20637-ce8d-4417-bec4-9b31b5e65092"), "Modify only his tenant.", new Guid("2f3509b7-160d-410a-b9b6-daadd96c986d"), true, "Modify Tenant" },
                    { new Guid("647145c6-2108-4c98-aab4-178602236e55"), "Asscess information related to tenant.", new Guid("2f3509b7-160d-410a-b9b6-daadd96c986d"), true, "View Tenant" },
                    { new Guid("d032cb1a-3f30-462c-bef0-7ace73a71c0b"), "Able add, modify and suspend any tenant.", new Guid("2f3509b7-160d-410a-b9b6-daadd96c986d"), true, "Manage Tenants" }
                });

            migrationBuilder.CreateIndex(
                name: "IX_Tenants_TenantStatusId",
                table: "Tenants",
                column: "TenantStatusId");

            migrationBuilder.AddForeignKey(
                name: "FK_Tenants_TenantStatus_TenantStatusId",
                table: "Tenants",
                column: "TenantStatusId",
                principalTable: "TenantStatus",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Tenants_TenantStatus_TenantStatusId",
                table: "Tenants");

            migrationBuilder.DropTable(
                name: "TenantStatus");

            migrationBuilder.DropIndex(
                name: "IX_Tenants_TenantStatusId",
                table: "Tenants");

            migrationBuilder.DeleteData(
                table: "FeaturePermissions",
                keyColumn: "Id",
                keyValue: new Guid("00e20637-ce8d-4417-bec4-9b31b5e65092"));

            migrationBuilder.DeleteData(
                table: "FeaturePermissions",
                keyColumn: "Id",
                keyValue: new Guid("647145c6-2108-4c98-aab4-178602236e55"));

            migrationBuilder.DeleteData(
                table: "FeaturePermissions",
                keyColumn: "Id",
                keyValue: new Guid("d032cb1a-3f30-462c-bef0-7ace73a71c0b"));

            migrationBuilder.DeleteData(
                table: "Features",
                keyColumn: "Id",
                keyValue: new Guid("2f3509b7-160d-410a-b9b6-daadd96c986d"));

            migrationBuilder.DeleteData(
                table: "Modules",
                keyColumn: "Id",
                keyValue: new Guid("f482a079-4dec-4f2d-9867-6baf2a4f23d9"));

            migrationBuilder.DropColumn(
                name: "BillingAddress",
                table: "Tenants");

            migrationBuilder.DropColumn(
                name: "CreatedById",
                table: "Tenants");

            migrationBuilder.DropColumn(
                name: "Email",
                table: "Tenants");

            migrationBuilder.DropColumn(
                name: "IsSuperTenant",
                table: "Tenants");

            migrationBuilder.DropColumn(
                name: "Reference",
                table: "Tenants");

            migrationBuilder.DropColumn(
                name: "TaxId",
                table: "Tenants");

            migrationBuilder.DropColumn(
                name: "TenantStatusId",
                table: "Tenants");

            migrationBuilder.DropColumn(
                name: "logoImage",
                table: "Tenants");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Tenants",
                type: "longtext",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "longtext")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "ContactNumber",
                table: "Tenants",
                type: "longtext",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "longtext")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "ContactName",
                table: "Tenants",
                type: "longtext",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "longtext")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");
        }
    }
}
