package dto

import "time"

type ListDeviceRequest 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:"每页数量"`
	DeviceNo       string     `json:"device_no" query:"device_no" validate:"omitempty,max=100" maxLength:"100" description:"设备号(模糊查询)"`
	DeviceName     string     `json:"device_name" query:"device_name" validate:"omitempty,max=255" maxLength:"255" description:"设备名称(模糊查询)"`
	Status         *int       `json:"status" query:"status" validate:"omitempty,min=1,max=4" minimum:"1" maximum:"4" description:"状态 (1:在库, 2:已分销, 3:已激活, 4:已停用)"`
	ShopID         *uint      `json:"shop_id" query:"shop_id" description:"店铺ID (NULL表示平台库存)"`
	SeriesID       *uint      `json:"series_id" query:"series_id" description:"套餐系列ID"`
	BatchNo        string     `json:"batch_no" query:"batch_no" validate:"omitempty,max=100" maxLength:"100" description:"批次号"`
	DeviceType     string     `json:"device_type" query:"device_type" validate:"omitempty,max=50" maxLength:"50" description:"设备类型"`
	Manufacturer   string     `json:"manufacturer" query:"manufacturer" validate:"omitempty,max=255" maxLength:"255" description:"制造商(模糊查询)"`
	CreatedAtStart *time.Time `json:"created_at_start" query:"created_at_start" description:"创建时间起始"`
	CreatedAtEnd   *time.Time `json:"created_at_end" query:"created_at_end" description:"创建时间结束"`
}

type DeviceResponse struct {
	ID                  uint       `json:"id" description:"设备ID"`
	DeviceNo            string     `json:"device_no" description:"设备号"`
	DeviceName          string     `json:"device_name" description:"设备名称"`
	DeviceModel         string     `json:"device_model" description:"设备型号"`
	DeviceType          string     `json:"device_type" description:"设备类型"`
	MaxSimSlots         int        `json:"max_sim_slots" description:"最大插槽数"`
	Manufacturer        string     `json:"manufacturer" description:"制造商"`
	BatchNo             string     `json:"batch_no" description:"批次号"`
	ShopID              *uint      `json:"shop_id,omitempty" description:"店铺ID"`
	ShopName            string     `json:"shop_name,omitempty" description:"店铺名称"`
	Status              int        `json:"status" description:"状态 (1:在库, 2:已分销, 3:已激活, 4:已停用)"`
	StatusName          string     `json:"status_name" description:"状态名称"`
	BoundCardCount      int        `json:"bound_card_count" description:"已绑定卡数量"`
	SeriesID            *uint      `json:"series_id,omitempty" description:"套餐系列ID"`
	FirstCommissionPaid bool       `json:"first_commission_paid" description:"一次性佣金是否已发放"`
	AccumulatedRecharge int64      `json:"accumulated_recharge" description:"累计充值金额(分)"`
	ActivatedAt         *time.Time `json:"activated_at,omitempty" description:"激活时间"`
	CreatedAt           time.Time  `json:"created_at" description:"创建时间"`
	UpdatedAt           time.Time  `json:"updated_at" description:"更新时间"`
}

type ListDeviceResponse struct {
	List       []*DeviceResponse `json:"list" description:"设备列表"`
	Total      int64             `json:"total" description:"总数"`
	Page       int               `json:"page" description:"当前页码"`
	PageSize   int               `json:"page_size" description:"每页数量"`
	TotalPages int               `json:"total_pages" description:"总页数"`
}

type GetDeviceRequest struct {
	ID uint `path:"id" description:"设备ID" required:"true"`
}

type GetDeviceByIMEIRequest struct {
	DeviceNo string `path:"imei" description:"设备号(IMEI)" required:"true"`
}

type DeleteDeviceRequest struct {
	ID uint `path:"id" description:"设备ID" required:"true"`
}

type ListDeviceCardsRequest struct {
	ID uint `path:"id" description:"设备ID" required:"true"`
}

type DeviceCardBindingResponse struct {
	ID           uint       `json:"id" description:"绑定记录ID"`
	SlotPosition int        `json:"slot_position" description:"插槽位置 (1-4)"`
	IotCardID    uint       `json:"iot_card_id" description:"IoT卡ID"`
	ICCID        string     `json:"iccid" description:"ICCID"`
	MSISDN       string     `json:"msisdn,omitempty" description:"接入号"`
	CarrierName  string     `json:"carrier_name,omitempty" description:"运营商名称"`
	Status       int        `json:"status" description:"卡状态 (1:在库, 2:已分销, 3:已激活, 4:已停用)"`
	BindTime     *time.Time `json:"bind_time,omitempty" description:"绑定时间"`
}

type ListDeviceCardsResponse struct {
	Bindings []*DeviceCardBindingResponse `json:"bindings" description:"绑定列表"`
}

type BindCardToDeviceRequest struct {
	ID           uint `path:"id" description:"设备ID" required:"true"`
	IotCardID    uint `json:"iot_card_id" validate:"required,min=1" required:"true" minimum:"1" description:"IoT卡ID"`
	SlotPosition int  `json:"slot_position" validate:"required,min=1,max=4" required:"true" minimum:"1" maximum:"4" description:"插槽位置 (1-4)"`
}

type BindCardToDeviceResponse struct {
	BindingID uint   `json:"binding_id" description:"绑定记录ID"`
	Message   string `json:"message" description:"提示信息"`
}

type UnbindCardFromDeviceRequest struct {
	ID     uint `path:"id" description:"设备ID" required:"true"`
	CardID uint `path:"cardId" description:"IoT卡ID" required:"true"`
}

type UnbindCardFromDeviceResponse struct {
	Message string `json:"message" description:"提示信息"`
}

type AllocateDevicesRequest struct {
	TargetShopID uint   `json:"target_shop_id" validate:"required,min=1" required:"true" minimum:"1" description:"目标店铺ID"`
	DeviceIDs    []uint `json:"device_ids" validate:"required,min=1,max=100" required:"true" minItems:"1" maxItems:"100" description:"设备ID列表"`
	Remark       string `json:"remark" validate:"omitempty,max=500" maxLength:"500" description:"备注"`
}

type AllocationDeviceFailedItem struct {
	DeviceID uint   `json:"device_id" description:"设备ID"`
	DeviceNo string `json:"device_no" description:"设备号"`
	Reason   string `json:"reason" description:"失败原因"`
}

type AllocateDevicesResponse struct {
	SuccessCount int                          `json:"success_count" description:"成功数量"`
	FailCount    int                          `json:"fail_count" description:"失败数量"`
	FailedItems  []AllocationDeviceFailedItem `json:"failed_items" description:"失败详情列表"`
}

type RecallDevicesRequest struct {
	DeviceIDs []uint `json:"device_ids" validate:"required,min=1,max=100" required:"true" minItems:"1" maxItems:"100" description:"设备ID列表"`
	Remark    string `json:"remark" validate:"omitempty,max=500" maxLength:"500" description:"备注"`
}

type RecallDevicesResponse struct {
	SuccessCount int                          `json:"success_count" description:"成功数量"`
	FailCount    int                          `json:"fail_count" description:"失败数量"`
	FailedItems  []AllocationDeviceFailedItem `json:"failed_items" description:"失败详情列表"`
}

// BatchSetDeviceSeriesBindngRequest 批量设置设备的套餐系列绑定请求
type BatchSetDeviceSeriesBindngRequest struct {
	DeviceIDs []uint `json:"device_ids" validate:"required,min=1,max=500,dive,required" required:"true" minItems:"1" maxItems:"500" description:"设备ID列表"`
	SeriesID  uint   `json:"series_id" validate:"required,min=0" required:"true" minimum:"0" description:"套餐系列ID（0表示清除关联）"`
}

// DeviceSeriesBindngFailedItem 设备系列绑定失败项
type DeviceSeriesBindngFailedItem struct {
	DeviceID uint   `json:"device_id" description:"设备ID"`
	DeviceNo string `json:"device_no" description:"设备号"`
	Reason   string `json:"reason" description:"失败原因"`
}

// BatchSetDeviceSeriesBindngResponse 批量设置设备的套餐系列绑定响应
type BatchSetDeviceSeriesBindngResponse struct {
	SuccessCount int                            `json:"success_count" description:"成功数量"`
	FailCount    int                            `json:"fail_count" description:"失败数量"`
	FailedItems  []DeviceSeriesBindngFailedItem `json:"failed_items" description:"失败详情列表"`
}

type SetSpeedLimitRequest struct {
	IMEI          string `path:"imei" description:"设备号(IMEI)" required:"true"`
	UploadSpeed   int    `json:"upload_speed" validate:"required,min=1" required:"true" minimum:"1" description:"上行速率（KB/s）"`
	DownloadSpeed int    `json:"download_speed" validate:"required,min=1" required:"true" minimum:"1" description:"下行速率（KB/s）"`
}

type SetWiFiRequest struct {
	IMEI     string `path:"imei" description:"设备号(IMEI)" required:"true"`
	SSID     string `json:"ssid" validate:"required,min=1,max=32" required:"true" minLength:"1" maxLength:"32" description:"WiFi 名称"`
	Password string `json:"password" validate:"required,min=8,max=63" required:"true" minLength:"8" maxLength:"63" description:"WiFi 密码"`
	Enabled  int    `json:"enabled" validate:"required,oneof=0 1" required:"true" description:"启用状态（0:禁用, 1:启用）"`
}

type SwitchCardRequest struct {
	IMEI        string `path:"imei" description:"设备号(IMEI)" required:"true"`
	TargetICCID string `json:"target_iccid" validate:"required" required:"true" description:"目标卡 ICCID"`
}

type EmptyResponse struct {
	Message string `json:"message,omitempty" description:"提示信息"`
}
