package dto

import (
	"time"

	"quyun/v2/app/requests"
	"quyun/v2/database/models"
	"quyun/v2/pkg/consts"
)

// AdminOrderListFilter defines query filters for tenant-admin order listing.
type AdminOrderListFilter struct {
	// Pagination controls paging parameters (page/limit).
	requests.Pagination `json:",inline" query:",inline"`
	// UserID filters orders by buyer user id.
	UserID *int64 `json:"user_id,omitempty" query:"user_id"`
	// ContentID filters orders by purchased content id (via order_items join).
	ContentID *int64 `json:"content_id,omitempty" query:"content_id"`
	// Status filters orders by order status.
	Status *consts.OrderStatus `json:"status,omitempty" query:"status"`
	// PaidAtFrom filters orders by paid_at >= this time.
	PaidAtFrom *time.Time `json:"paid_at_from,omitempty" query:"paid_at_from"`
	// PaidAtTo filters orders by paid_at <= this time.
	PaidAtTo *time.Time `json:"paid_at_to,omitempty" query:"paid_at_to"`
	// AmountPaidMin filters orders by amount_paid >= this amount (cents).
	AmountPaidMin *int64 `json:"amount_paid_min,omitempty" query:"amount_paid_min"`
	// AmountPaidMax filters orders by amount_paid <= this amount (cents).
	AmountPaidMax *int64 `json:"amount_paid_max,omitempty" query:"amount_paid_max"`
}

// AdminOrderRefundForm defines payload for tenant-admin to refund an order.
type AdminOrderRefundForm struct {
	// Force indicates bypassing the default refund window check (paid_at + 24h).
	// 强制退款：true 表示绕过默认退款时间窗限制（需审计）。
	Force bool `json:"force,omitempty"`
	// Reason is the human-readable refund reason used for audit.
	// 退款原因：建议必填（由业务侧校验）；用于审计与追责。
	Reason string `json:"reason,omitempty"`
	// IdempotencyKey ensures refund request is processed at most once.
	// 幂等键：同一笔退款重复请求时返回一致结果，避免重复退款/重复回滚。
	IdempotencyKey string `json:"idempotency_key,omitempty"`
}

// AdminOrderDetail returns a tenant-admin order detail payload.
type AdminOrderDetail struct {
	// Order is the order with items preloaded.
	Order *models.Order `json:"order,omitempty"`
}
