using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Meezi.Infrastructure.Data.Migrations
{
    /// <inheritdoc />
    public partial class GrowthOpsFeatures : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "KitchenStationId",
                table: "MenuCategories",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "DiscoverBadgesJson",
                table: "Cafes",
                type: "character varying(2000)",
                maxLength: 2000,
                nullable: true);

            migrationBuilder.AddColumn<bool>(
                name: "IsHidden",
                table: "CafeReviews",
                type: "boolean",
                nullable: false,
                defaultValue: false);

            migrationBuilder.CreateTable(
                name: "CafeReviewPhotos",
                columns: table => new
                {
                    Id = table.Column<string>(type: "text", nullable: false),
                    ReviewId = table.Column<string>(type: "text", nullable: false),
                    Url = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
                    SortOrder = table.Column<int>(type: "integer", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CafeReviewPhotos", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CafeReviewPhotos_CafeReviews_ReviewId",
                        column: x => x.ReviewId,
                        principalTable: "CafeReviews",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ConsumerAccounts",
                columns: table => new
                {
                    Id = table.Column<string>(type: "text", nullable: false),
                    Phone = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
                    Name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ConsumerAccounts", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "KitchenStations",
                columns: table => new
                {
                    Id = table.Column<string>(type: "text", nullable: false),
                    BranchId = table.Column<string>(type: "text", nullable: true),
                    Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    PrinterIp = table.Column<string>(type: "character varying(45)", maxLength: 45, nullable: true),
                    PrinterPort = table.Column<int>(type: "integer", nullable: false),
                    SortOrder = table.Column<int>(type: "integer", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    CafeId = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KitchenStations", x => x.Id);
                    table.ForeignKey(
                        name: "FK_KitchenStations_Branches_BranchId",
                        column: x => x.BranchId,
                        principalTable: "Branches",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_KitchenStations_Cafes_CafeId",
                        column: x => x.CafeId,
                        principalTable: "Cafes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MenuCategories_KitchenStationId",
                table: "MenuCategories",
                column: "KitchenStationId");

            migrationBuilder.CreateIndex(
                name: "IX_CafeReviewPhotos_ReviewId",
                table: "CafeReviewPhotos",
                column: "ReviewId");

            migrationBuilder.CreateIndex(
                name: "IX_ConsumerAccounts_Phone",
                table: "ConsumerAccounts",
                column: "Phone",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_KitchenStations_BranchId",
                table: "KitchenStations",
                column: "BranchId");

            migrationBuilder.CreateIndex(
                name: "IX_KitchenStations_CafeId_SortOrder",
                table: "KitchenStations",
                columns: new[] { "CafeId", "SortOrder" });

            migrationBuilder.AddForeignKey(
                name: "FK_MenuCategories_KitchenStations_KitchenStationId",
                table: "MenuCategories",
                column: "KitchenStationId",
                principalTable: "KitchenStations",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);
        }

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

            migrationBuilder.DropTable(
                name: "CafeReviewPhotos");

            migrationBuilder.DropTable(
                name: "ConsumerAccounts");

            migrationBuilder.DropTable(
                name: "KitchenStations");

            migrationBuilder.DropIndex(
                name: "IX_MenuCategories_KitchenStationId",
                table: "MenuCategories");

            migrationBuilder.DropColumn(
                name: "KitchenStationId",
                table: "MenuCategories");

            migrationBuilder.DropColumn(
                name: "DiscoverBadgesJson",
                table: "Cafes");

            migrationBuilder.DropColumn(
                name: "IsHidden",
                table: "CafeReviews");
        }
    }
}
