using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Meezi.Infrastructure.Data.Migrations
{
    /// <inheritdoc />
    public partial class OrderNotificationsAndGuestTracking : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "GuestTrackingToken",
                table: "Orders",
                type: "character varying(64)",
                maxLength: 64,
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "StatusUpdatedAt",
                table: "Orders",
                type: "timestamp with time zone",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.CreateTable(
                name: "CafeNotifications",
                columns: table => new
                {
                    Id = table.Column<string>(type: "text", nullable: false),
                    Type = table.Column<string>(type: "character varying(60)", maxLength: 60, nullable: false),
                    Title = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
                    Body = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
                    ReferenceId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    TableNumber = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true),
                    IsRead = table.Column<bool>(type: "boolean", nullable: false),
                    ReadAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    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_CafeNotifications", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Orders_GuestTrackingToken",
                table: "Orders",
                column: "GuestTrackingToken");

            migrationBuilder.CreateIndex(
                name: "IX_CafeNotifications_CafeId_IsRead_CreatedAt",
                table: "CafeNotifications",
                columns: new[] { "CafeId", "IsRead", "CreatedAt" });
        }

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

            migrationBuilder.DropIndex(
                name: "IX_Orders_GuestTrackingToken",
                table: "Orders");

            migrationBuilder.DropColumn(
                name: "GuestTrackingToken",
                table: "Orders");

            migrationBuilder.DropColumn(
                name: "StatusUpdatedAt",
                table: "Orders");
        }
    }
}
