package region_sync

// SyncUserRequest 创建同步用户的请求
type SyncUserRequest struct {
	Username     string `json:"username"`
	Email        string `json:"email"`
	PasswordHash string `json:"password_hash"`
	DisplayName  string `json:"display_name"`
	Quota        int    `json:"quota"`
	RemoteUserId int    `json:"remote_user_id"`
	Group        string `json:"group"`
	AffCode      string `json:"aff_code"`
}

// SyncUserResponse 创建同步用户的响应
type SyncUserResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message,omitempty"`
	Error   string `json:"error,omitempty"`
}

// QueryQuotaRequest 查询余额请求
type QueryQuotaRequest struct {
	UserId int `json:"user_id"`
}

// QueryQuotaResponse 查询余额响应
type QueryQuotaResponse struct {
	Success bool   `json:"success"`
	Quota   int    `json:"quota"`
	Error   string `json:"error,omitempty"`
}

// BatchDeductRecord 批量扣费记录
type BatchDeductRecord struct {
	UserId    int    `json:"user_id"`
	RequestId string `json:"request_id"`
	Quota     int    `json:"quota"`
}

// BatchDeductRequest 批量扣费请求
type BatchDeductRequest struct {
	Records []BatchDeductRecord `json:"records"`
}

// DeductResult 单条扣费结果
type DeductResult struct {
	UserId         int    `json:"user_id"`
	Success        bool   `json:"success"`
	DeductedQuota int    `json:"deducted_quota,omitempty"`
	RemainingQuota int    `json:"remaining_quota,omitempty"`
	Error          string `json:"error,omitempty"`
	Message        string `json:"message,omitempty"`
}

// BatchDeductResponse 批量扣费响应
type BatchDeductResponse struct {
	Success bool           `json:"success"`
	Results []DeductResult `json:"results"`
	Error   string         `json:"error,omitempty"`
}

// UpdateQuotaRequest 更新同步余额请求
type UpdateQuotaRequest struct {
	RemoteUserId int `json:"remote_user_id"`
	Quota        int `json:"quota"`
}

// UpdateQuotaResponse 更新同步余额响应
type UpdateQuotaResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
}

// SyncConfigResponse Master 下发给 Slave 的配置
type SyncConfigResponse struct {
	Success              bool `json:"success"`
	MinBalanceThreshold  int  `json:"min_balance_threshold"`
	MaxRetryCount        int  `json:"max_retry_count"`
	SyncBatchSize        int  `json:"sync_batch_size"`
	SyncIntervalSeconds  int  `json:"sync_interval_seconds"`
	Error                string `json:"error,omitempty"`
}

// QuotaEntry 单个用户的余额信息
type QuotaEntry struct {
	UserId int `json:"user_id"`
	Quota  int `json:"quota"`
}

// BatchQueryQuotaRequest 批量查询余额请求
type BatchQueryQuotaRequest struct {
	UserIds []int `json:"user_ids"`
}

// BatchQueryQuotaResponse 批量查询余额响应
type BatchQueryQuotaResponse struct {
	Success bool         `json:"success"`
	Quotas  []QuotaEntry `json:"quotas"`
	Error   string       `json:"error,omitempty"`
}
