package queue

import (
	"context"

	cardObservationApp "github.com/break/junhong_cmp_fiber/internal/application/cardobservation"
	"github.com/break/junhong_cmp_fiber/internal/service/commission_calculation"
	"github.com/break/junhong_cmp_fiber/internal/service/commission_stats"
	packagepkg "github.com/break/junhong_cmp_fiber/internal/service/package"
	pollingSvc "github.com/break/junhong_cmp_fiber/internal/service/polling"
	"github.com/break/junhong_cmp_fiber/internal/store/postgres"
	"github.com/break/junhong_cmp_fiber/internal/task"
)

// OrderExpirer 订单超时取消接口
// 解耦 pkg/queue 与 internal/service/order 之间的循环依赖
type OrderExpirer interface {
	// CancelExpiredOrders 批量取消已超时的待支付订单，返回取消数量
	CancelExpiredOrders(ctx context.Context) (int, error)
}

// WorkerStores Worker 侧所有 Store 的集合
type WorkerStores struct {
	AssetOperationLog          *postgres.AssetOperationLogStore
	AssetAllocationRecord      *postgres.AssetAllocationRecordStore
	IotCardImportTask          *postgres.IotCardImportTaskStore
	IotCard                    *postgres.IotCardStore
	DeviceImportTask           *postgres.DeviceImportTaskStore
	ExportTask                 *postgres.ExportTaskStore
	ExportShardTask            *postgres.ExportShardTaskStore
	Device                     *postgres.DeviceStore
	DeviceSimBinding           *postgres.DeviceSimBindingStore
	ShopSeriesCommissionStats  *postgres.ShopSeriesCommissionStatsStore
	ShopPackageAllocation      *postgres.ShopPackageAllocationStore
	CommissionRecord           *postgres.CommissionRecordStore
	Shop                       *postgres.ShopStore
	ShopSeriesAllocation       *postgres.ShopSeriesAllocationStore
	PackageSeries              *postgres.PackageSeriesStore
	Order                      *postgres.OrderStore
	OrderItem                  *postgres.OrderItemStore
	Package                    *postgres.PackageStore
	PackageUsage               *postgres.PackageUsageStore
	PackageUsageDailyRecord    *postgres.PackageUsageDailyRecordStore
	PollingAlertRule           *postgres.PollingAlertRuleStore
	PollingAlertHistory        *postgres.PollingAlertHistoryStore
	DataCleanupConfig          *postgres.DataCleanupConfigStore
	DataCleanupLog             *postgres.DataCleanupLogStore
	AgentWallet                *postgres.AgentWalletStore
	AgentWalletTransaction     *postgres.AgentWalletTransactionStore
	AssetWallet                *postgres.AssetWalletStore
	AssetIdentifier            *postgres.AssetIdentifierStore
	PersonalCustomer           *postgres.PersonalCustomerStore
	PersonalCustomerPhone      *postgres.PersonalCustomerPhoneStore
	OrderPackageInvalidateTask *postgres.OrderPackageInvalidateTaskStore
	AssetPackageBatchOrderTask *postgres.AssetPackageBatchOrderTaskStore
}

// WorkerServices Worker 侧所有 Service 的集合
type WorkerServices struct {
	CardObservation          *cardObservationApp.Service
	CardObservationSeries    *cardObservationApp.SeriesAttemptService
	ObservationSeriesEvents  cardObservationApp.SeriesEventWriter
	CommissionCalculation    *commission_calculation.Service
	CommissionStats          *commission_stats.Service
	UsageService             *packagepkg.UsageService
	ActivationService        *packagepkg.ActivationService
	ResetService             *packagepkg.ResetService
	AlertService             *pollingSvc.AlertService
	CleanupService           *pollingSvc.CleanupService
	StopResumeService        packagepkg.StopResumeCallback      // 停复机服务，用于注入 Scheduler
	OrderExpirer             OrderExpirer                       // 订单超时取消服务（接口类型，避免循环依赖）
	AssetPackageOrderCreator task.AssetPackageBatchOrderCreator // 批量订购复用后台单笔订单规则
	DeviceBatchAllocator     task.DeviceBatchAllocationExecutor // 设备CSV批量分配复用现有业务规则
}

// WorkerBootstrapResult Worker Bootstrap 结果
type WorkerBootstrapResult struct {
	Stores   *WorkerStores
	Services *WorkerServices
}
