using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TakeoutSaaS.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddGeoLocationRetryMetadata : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "GeoFailReason",
                table: "tenants",
                type: "character varying(500)",
                maxLength: 500,
                nullable: true,
                comment: "地理定位失败原因。");

            migrationBuilder.AddColumn<DateTime>(
                name: "GeoNextRetryAt",
                table: "tenants",
                type: "timestamp with time zone",
                nullable: true,
                comment: "下次地理定位重试时间（UTC）。");

            migrationBuilder.AddColumn<int>(
                name: "GeoRetryCount",
                table: "tenants",
                type: "integer",
                nullable: false,
                defaultValue: 0,
                comment: "地理定位重试次数。");

            migrationBuilder.AddColumn<int>(
                name: "GeoStatus",
                table: "tenants",
                type: "integer",
                nullable: false,
                defaultValue: 0,
                comment: "地理定位状态。");

            migrationBuilder.AddColumn<DateTime>(
                name: "GeoUpdatedAt",
                table: "tenants",
                type: "timestamp with time zone",
                nullable: true,
                comment: "地理定位最近成功时间（UTC）。");

            migrationBuilder.AddColumn<double>(
                name: "Latitude",
                table: "tenants",
                type: "double precision",
                nullable: true,
                comment: "纬度信息。");

            migrationBuilder.AddColumn<double>(
                name: "Longitude",
                table: "tenants",
                type: "double precision",
                nullable: true,
                comment: "经度信息。");

            migrationBuilder.AddColumn<string>(
                name: "GeoFailReason",
                table: "stores",
                type: "character varying(500)",
                maxLength: 500,
                nullable: true,
                comment: "地理定位失败原因。");

            migrationBuilder.AddColumn<DateTime>(
                name: "GeoNextRetryAt",
                table: "stores",
                type: "timestamp with time zone",
                nullable: true,
                comment: "下次地理定位重试时间（UTC）。");

            migrationBuilder.AddColumn<int>(
                name: "GeoRetryCount",
                table: "stores",
                type: "integer",
                nullable: false,
                defaultValue: 0,
                comment: "地理定位重试次数。");

            migrationBuilder.AddColumn<int>(
                name: "GeoStatus",
                table: "stores",
                type: "integer",
                nullable: false,
                defaultValue: 0,
                comment: "地理定位状态。");

            migrationBuilder.AddColumn<DateTime>(
                name: "GeoUpdatedAt",
                table: "stores",
                type: "timestamp with time zone",
                nullable: true,
                comment: "地理定位最近成功时间（UTC）。");

            migrationBuilder.AddColumn<string>(
                name: "GeoFailReason",
                table: "merchants",
                type: "character varying(500)",
                maxLength: 500,
                nullable: true,
                comment: "地理定位失败原因。");

            migrationBuilder.AddColumn<DateTime>(
                name: "GeoNextRetryAt",
                table: "merchants",
                type: "timestamp with time zone",
                nullable: true,
                comment: "下次地理定位重试时间（UTC）。");

            migrationBuilder.AddColumn<int>(
                name: "GeoRetryCount",
                table: "merchants",
                type: "integer",
                nullable: false,
                defaultValue: 0,
                comment: "地理定位重试次数。");

            migrationBuilder.AddColumn<int>(
                name: "GeoStatus",
                table: "merchants",
                type: "integer",
                nullable: false,
                defaultValue: 0,
                comment: "地理定位状态。");

            migrationBuilder.AddColumn<DateTime>(
                name: "GeoUpdatedAt",
                table: "merchants",
                type: "timestamp with time zone",
                nullable: true,
                comment: "地理定位最近成功时间（UTC）。");

            migrationBuilder.CreateIndex(
                name: "IX_tenants_GeoStatus_GeoNextRetryAt",
                table: "tenants",
                columns: new[] { "GeoStatus", "GeoNextRetryAt" });

            migrationBuilder.CreateIndex(
                name: "IX_tenants_Longitude_Latitude",
                table: "tenants",
                columns: new[] { "Longitude", "Latitude" },
                filter: "\"Longitude\" IS NOT NULL AND \"Latitude\" IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_stores_TenantId_MerchantId_GeoStatus_GeoNextRetryAt",
                table: "stores",
                columns: new[] { "TenantId", "MerchantId", "GeoStatus", "GeoNextRetryAt" });

            migrationBuilder.CreateIndex(
                name: "IX_merchants_Longitude_Latitude",
                table: "merchants",
                columns: new[] { "Longitude", "Latitude" },
                filter: "\"Longitude\" IS NOT NULL AND \"Latitude\" IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_merchants_TenantId_GeoStatus_GeoNextRetryAt",
                table: "merchants",
                columns: new[] { "TenantId", "GeoStatus", "GeoNextRetryAt" });
        }

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

            migrationBuilder.DropIndex(
                name: "IX_tenants_Longitude_Latitude",
                table: "tenants");

            migrationBuilder.DropIndex(
                name: "IX_stores_TenantId_MerchantId_GeoStatus_GeoNextRetryAt",
                table: "stores");

            migrationBuilder.DropIndex(
                name: "IX_merchants_Longitude_Latitude",
                table: "merchants");

            migrationBuilder.DropIndex(
                name: "IX_merchants_TenantId_GeoStatus_GeoNextRetryAt",
                table: "merchants");

            migrationBuilder.DropColumn(
                name: "GeoFailReason",
                table: "tenants");

            migrationBuilder.DropColumn(
                name: "GeoNextRetryAt",
                table: "tenants");

            migrationBuilder.DropColumn(
                name: "GeoRetryCount",
                table: "tenants");

            migrationBuilder.DropColumn(
                name: "GeoStatus",
                table: "tenants");

            migrationBuilder.DropColumn(
                name: "GeoUpdatedAt",
                table: "tenants");

            migrationBuilder.DropColumn(
                name: "Latitude",
                table: "tenants");

            migrationBuilder.DropColumn(
                name: "Longitude",
                table: "tenants");

            migrationBuilder.DropColumn(
                name: "GeoFailReason",
                table: "stores");

            migrationBuilder.DropColumn(
                name: "GeoNextRetryAt",
                table: "stores");

            migrationBuilder.DropColumn(
                name: "GeoRetryCount",
                table: "stores");

            migrationBuilder.DropColumn(
                name: "GeoStatus",
                table: "stores");

            migrationBuilder.DropColumn(
                name: "GeoUpdatedAt",
                table: "stores");

            migrationBuilder.DropColumn(
                name: "GeoFailReason",
                table: "merchants");

            migrationBuilder.DropColumn(
                name: "GeoNextRetryAt",
                table: "merchants");

            migrationBuilder.DropColumn(
                name: "GeoRetryCount",
                table: "merchants");

            migrationBuilder.DropColumn(
                name: "GeoStatus",
                table: "merchants");

            migrationBuilder.DropColumn(
                name: "GeoUpdatedAt",
                table: "merchants");
        }
    }
}
