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 获取)"`
}

type ImportDeviceResponse 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:失败)"`
	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:"任务编号"`
	Status       int        `json:"status" description:"任务状态 (1:待处理, 2:处理中, 3:已完成, 4:失败)"`
	StatusText   string     `json:"status_text" description:"任务状态文本"`
	BatchNo      string     `json:"batch_no,omitempty" description:"批次号"`
	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:"错误信息"`
	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:"设备虚拟号"`
	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:"警告记录详情(部分成功的设备及其卡绑定失败原因)"`
}
