package dto

import "time"

type ImportDeviceRequest struct {
	BatchNo        string `json:"batch_no" validate:"omitempty,max=100" maxLength:"100" description:"批次号"`
	FileKey        string `json:"file_key" validate:"required,min=1,max=500" required:"true" minLength:"1" maxLength:"500" description:"对象存储文件路径(通过 /storage/upload-url 获取)"`
	RealnamePolicy string `json:"realname_policy" validate:"omitempty,oneof=none before_order after_order" description:"实名认证策略 (none:无需实名, before_order:先实名后充值/购买, after_order:先充值/购买后实名)，默认 after_order"`
}

type ImportDeviceResponse struct {
	TaskID  uint   `json:"task_id" description:"导入任务ID"`
	TaskNo  string `json:"task_no" description:"任务编号"`
	Message string `json:"message" description:"提示信息"`
}

// CreateDeviceBatchAllocationRequest 创建设备 CSV 批量分配任务请求。
type CreateDeviceBatchAllocationRequest struct {
	FileKey       string `json:"file_key" validate:"required,min=1,max=500" required:"true" minLength:"1" maxLength:"500" description:"单列设备标识 CSV 对象存储 Key（每行支持 VirtualNo、IMEI 或 SN）"`
	OperationType string `json:"operation_type" validate:"required,oneof=assign_shop assign_series" required:"true" enum:"assign_shop,assign_series" description:"操作类型 (assign_shop:分配目标代理, assign_series:设置套餐系列)"`
	TargetID      uint   `json:"target_id" validate:"required,min=1" required:"true" minimum:"1" description:"目标代理店铺ID或套餐系列ID，由 operation_type 决定"`
}

// CreateDeviceBatchAllocationResponse 创建设备 CSV 批量分配任务响应。
type CreateDeviceBatchAllocationResponse struct {
	TaskID  uint   `json:"task_id" description:"任务ID"`
	TaskNo  string `json:"task_no" description:"任务编号"`
	Message string `json:"message" description:"提示信息"`
}

type ListDeviceImportTaskRequest struct {
	Page          int        `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码"`
	PageSize      int        `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量"`
	Status        *int       `json:"status" query:"status" validate:"omitempty,min=1,max=4" minimum:"1" maximum:"4" description:"任务状态 (1:待处理, 2:处理中, 3:已完成, 4:失败)"`
	OperationType string     `json:"operation_type" query:"operation_type" validate:"omitempty,oneof=import assign_shop assign_series" enum:"import,assign_shop,assign_series" description:"任务业务类型 (import:导入设备, assign_shop:分配目标代理, assign_series:设置套餐系列)"`
	BatchNo       string     `json:"batch_no" query:"batch_no" validate:"omitempty,max=100" maxLength:"100" description:"批次号(模糊查询)"`
	StartTime     *time.Time `json:"start_time" query:"start_time" description:"创建时间起始"`
	EndTime       *time.Time `json:"end_time" query:"end_time" description:"创建时间结束"`
}

type DeviceImportTaskResponse struct {
	ID             uint       `json:"id" description:"任务ID"`
	TaskNo         string     `json:"task_no" description:"任务编号"`
	OperationType  string     `json:"operation_type" description:"任务业务类型 (import:导入设备, assign_shop:分配目标代理, assign_series:设置套餐系列)"`
	OperationName  string     `json:"operation_name" description:"任务业务类型名称（中文）"`
	TargetID       *uint      `json:"target_id,omitempty" description:"批量分配目标店铺或套餐系列ID"`
	Status         int        `json:"status" description:"任务状态 (1:待处理, 2:处理中, 3:已完成, 4:失败)"`
	StatusName     string     `json:"status_name" description:"任务状态名称（中文）"`
	StatusText     string     `json:"status_text" description:"任务状态文本"`
	BatchNo        string     `json:"batch_no,omitempty" description:"批次号"`
	RealnamePolicy string     `json:"realname_policy" description:"实名认证策略 (none:无需实名, before_order:先实名后充值/购买, after_order:先充值/购买后实名)"`
	FileName       string     `json:"file_name,omitempty" description:"文件名"`
	TotalCount     int        `json:"total_count" description:"总数"`
	SuccessCount   int        `json:"success_count" description:"成功数"`
	SkipCount      int        `json:"skip_count" description:"跳过数"`
	FailCount      int        `json:"fail_count" description:"失败数"`
	WarningCount   int        `json:"warning_count" description:"警告数(部分成功的设备数量)"`
	StartedAt      *time.Time `json:"started_at,omitempty" description:"开始处理时间"`
	CompletedAt    *time.Time `json:"completed_at,omitempty" description:"完成时间"`
	ErrorMessage   string     `json:"error_message,omitempty" description:"错误信息"`
	CreatorName    string     `json:"creator_name" description:"操作人姓名"`
	CreatedAt      time.Time  `json:"created_at" description:"创建时间"`
}

type ListDeviceImportTaskResponse struct {
	List     []*DeviceImportTaskResponse `json:"items" description:"任务列表"`
	Total    int64                       `json:"total" description:"总数"`
	Page     int                         `json:"page" description:"当前页码"`
	PageSize int                         `json:"size" description:"每页数量"`
}

type DeviceImportResultItemDTO struct {
	Line             int    `json:"line" description:"行号"`
	VirtualNo        string `json:"virtual_no" description:"设备虚拟号（兼容原设备导入任务字段）"`
	DeviceIdentifier string `json:"device_identifier" description:"CSV原始设备标识（VirtualNo、IMEI或SN）"`
	Reason           string `json:"reason" description:"原因"`
}

type GetDeviceImportTaskRequest struct {
	ID uint `path:"id" description:"任务ID" required:"true"`
}

type DeviceImportTaskDetailResponse struct {
	DeviceImportTaskResponse
	SkippedItems []*DeviceImportResultItemDTO `json:"skipped_items" description:"跳过记录详情"`
	FailedItems  []*DeviceImportResultItemDTO `json:"failed_items" description:"失败记录详情"`
	WarningItems []*DeviceImportResultItemDTO `json:"warning_items" description:"警告记录详情(部分成功的设备及其卡绑定失败原因)"`
}
