using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TakeoutSaaS.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class ExtendStoreHolidayForTemporaryHours : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropIndex(
                name: "IX_store_holidays_TenantId_StoreId_Date",
                table: "store_holidays");

            migrationBuilder.AlterTable(
                name: "store_holidays",
                comment: "门店临时时段配置（节假日/歇业/调整营业时间）。",
                oldComment: "门店休息日或特殊营业日。");

            migrationBuilder.AlterColumn<string>(
                name: "Reason",
                table: "store_holidays",
                type: "character varying(200)",
                maxLength: 200,
                nullable: true,
                comment: "说明内容。",
                oldClrType: typeof(string),
                oldType: "character varying(256)",
                oldMaxLength: 256,
                oldNullable: true,
                oldComment: "说明内容。");

            migrationBuilder.AlterColumn<bool>(
                name: "IsClosed",
                table: "store_holidays",
                type: "boolean",
                nullable: false,
                defaultValue: true,
                comment: "是否闭店（兼容旧数据，新逻辑请用 OverrideType）。",
                oldClrType: typeof(bool),
                oldType: "boolean",
                oldComment: "是否全天闭店。");

            migrationBuilder.AlterColumn<DateTime>(
                name: "Date",
                table: "store_holidays",
                type: "timestamp with time zone",
                nullable: false,
                comment: "开始日期（原 Date 字段）。",
                oldClrType: typeof(DateTime),
                oldType: "timestamp with time zone",
                oldComment: "日期。");

            migrationBuilder.AddColumn<DateTime>(
                name: "EndDate",
                table: "store_holidays",
                type: "timestamp with time zone",
                nullable: true,
                comment: "结束日期（可选，用于日期范围，如春节 1.28~2.4）。");

            migrationBuilder.AddColumn<TimeSpan>(
                name: "EndTime",
                table: "store_holidays",
                type: "interval",
                nullable: true,
                comment: "结束时间（IsAllDay=false 时使用）。");

            migrationBuilder.AddColumn<bool>(
                name: "IsAllDay",
                table: "store_holidays",
                type: "boolean",
                nullable: false,
                defaultValue: true,
                comment: "是否全天生效。true=全天；false=仅 StartTime~EndTime 时段。");

            migrationBuilder.AddColumn<int>(
                name: "OverrideType",
                table: "store_holidays",
                type: "integer",
                nullable: false,
                defaultValue: 0,
                comment: "覆盖类型（闭店/临时营业/调整时间）。");

            migrationBuilder.AddColumn<TimeSpan>(
                name: "StartTime",
                table: "store_holidays",
                type: "interval",
                nullable: true,
                comment: "开始时间（IsAllDay=false 时使用）。");

            migrationBuilder.CreateIndex(
                name: "IX_store_holidays_TenantId_StoreId_Date",
                table: "store_holidays",
                columns: new[] { "TenantId", "StoreId", "Date" });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropIndex(
                name: "IX_store_holidays_TenantId_StoreId_Date",
                table: "store_holidays");

            migrationBuilder.DropColumn(
                name: "EndDate",
                table: "store_holidays");

            migrationBuilder.DropColumn(
                name: "EndTime",
                table: "store_holidays");

            migrationBuilder.DropColumn(
                name: "IsAllDay",
                table: "store_holidays");

            migrationBuilder.DropColumn(
                name: "OverrideType",
                table: "store_holidays");

            migrationBuilder.DropColumn(
                name: "StartTime",
                table: "store_holidays");

            migrationBuilder.AlterTable(
                name: "store_holidays",
                comment: "门店休息日或特殊营业日。",
                oldComment: "门店临时时段配置（节假日/歇业/调整营业时间）。");

            migrationBuilder.AlterColumn<string>(
                name: "Reason",
                table: "store_holidays",
                type: "character varying(256)",
                maxLength: 256,
                nullable: true,
                comment: "说明内容。",
                oldClrType: typeof(string),
                oldType: "character varying(200)",
                oldMaxLength: 200,
                oldNullable: true,
                oldComment: "说明内容。");

            migrationBuilder.AlterColumn<bool>(
                name: "IsClosed",
                table: "store_holidays",
                type: "boolean",
                nullable: false,
                comment: "是否全天闭店。",
                oldClrType: typeof(bool),
                oldType: "boolean",
                oldDefaultValue: true,
                oldComment: "是否闭店（兼容旧数据，新逻辑请用 OverrideType）。");

            migrationBuilder.AlterColumn<DateTime>(
                name: "Date",
                table: "store_holidays",
                type: "timestamp with time zone",
                nullable: false,
                comment: "日期。",
                oldClrType: typeof(DateTime),
                oldType: "timestamp with time zone",
                oldComment: "开始日期（原 Date 字段）。");

            migrationBuilder.CreateIndex(
                name: "IX_store_holidays_TenantId_StoreId_Date",
                table: "store_holidays",
                columns: new[] { "TenantId", "StoreId", "Date" },
                unique: true);
        }
    }
}
