package dto

import "time"

// AllocateDevicesReq 企业授权设备请求，支持 list/filter 两种模式
type AllocateDevicesReq struct {
	ID            uint     `json:"-" params:"id" path:"id" validate:"required" required:"true" description:"企业ID"`
	SelectionType string   `json:"selection_type" validate:"required,oneof=list filter" required:"true" description:"选取模式 (list:指定设备号列表, filter:按条件过滤)"`
	DeviceNos     []string `json:"device_nos" validate:"omitempty,max=100" description:"[list模式] 设备号列表（最多100个）"`
	VirtualNo     string   `json:"virtual_no" validate:"omitempty,max=100" maxLength:"100" description:"[filter模式] 设备虚拟号（模糊匹配）"`
	BatchNo       string   `json:"batch_no" validate:"omitempty,max=100" maxLength:"100" description:"[filter模式] 批次号"`
	ShopID        *uint    `json:"shop_id" description:"[filter模式] 店铺ID"`
	Remark        string   `json:"remark" validate:"omitempty,max=500" maxLength:"500" description:"授权备注（所有模式均可选）"`
}

type AllocateDevicesResp struct {
	SuccessCount      int                    `json:"success_count" description:"成功数量"`
	FailCount         int                    `json:"fail_count" description:"失败数量"`
	FailedItems       []FailedDeviceItem     `json:"failed_items" description:"失败项列表"`
	AuthorizedDevices []AuthorizedDeviceItem `json:"authorized_devices" description:"已授权设备列表"`
}

type FailedDeviceItem struct {
	VirtualNo string `json:"virtual_no" description:"设备虚拟号"`
	Reason    string `json:"reason" description:"失败原因"`
}

type AuthorizedDeviceItem struct {
	DeviceID  uint   `json:"device_id" description:"设备ID"`
	VirtualNo string `json:"virtual_no" description:"设备虚拟号"`
	CardCount int    `json:"card_count" description:"绑定卡数量"`
}

// RecallDevicesReq 企业收回设备授权请求，支持 list/filter 两种模式
type RecallDevicesReq struct {
	ID            uint     `json:"-" params:"id" path:"id" validate:"required" required:"true" description:"企业ID"`
	SelectionType string   `json:"selection_type" validate:"required,oneof=list filter" required:"true" description:"选取模式 (list:指定设备号列表, filter:按条件过滤)"`
	DeviceNos     []string `json:"device_nos" validate:"omitempty,max=100" description:"[list模式] 设备号列表（最多100个）"`
	VirtualNo     string   `json:"virtual_no" validate:"omitempty,max=100" maxLength:"100" description:"[filter模式] 设备虚拟号（模糊匹配）"`
	BatchNo       string   `json:"batch_no" validate:"omitempty,max=100" maxLength:"100" description:"[filter模式] 批次号"`
}

type RecallDevicesResp struct {
	SuccessCount int                `json:"success_count" description:"成功数量"`
	FailCount    int                `json:"fail_count" description:"失败数量"`
	FailedItems  []FailedDeviceItem `json:"failed_items" description:"失败项列表"`
}

type EnterpriseDeviceListReq struct {
	ID        uint   `json:"-" params:"id" path:"id" validate:"required" required:"true" description:"企业ID"`
	Page      int    `json:"page" query:"page" validate:"required,min=1" description:"页码"`
	PageSize  int    `json:"page_size" query:"page_size" validate:"required,min=1,max=100" description:"每页数量"`
	VirtualNo string `json:"virtual_no" query:"virtual_no" description:"虚拟号（模糊搜索）"`
}

type H5EnterpriseDeviceListReq struct {
	Page      int    `json:"page" query:"page" validate:"required,min=1" description:"页码"`
	PageSize  int    `json:"page_size" query:"page_size" validate:"required,min=1,max=100" description:"每页数量"`
	VirtualNo string `json:"virtual_no" query:"virtual_no" description:"虚拟号（模糊搜索）"`
}

type EnterpriseDeviceListResp struct {
	List  []EnterpriseDeviceItem `json:"items" description:"设备列表"`
	Total int64                  `json:"total" description:"总数"`
}

type EnterpriseDeviceItem struct {
	DeviceID     uint      `json:"device_id" description:"设备ID"`
	VirtualNo    string    `json:"virtual_no" description:"设备虚拟号"`
	DeviceName   string    `json:"device_name" description:"设备名称"`
	DeviceModel  string    `json:"device_model" description:"设备型号"`
	CardCount    int       `json:"card_count" description:"绑定卡数量"`
	AuthorizedAt time.Time `json:"authorized_at" description:"授权时间"`
}

type EnterpriseDeviceDetailResp struct {
	Device EnterpriseDeviceInfo `json:"device" description:"设备信息"`
	Cards  []DeviceCardInfo     `json:"cards" description:"绑定卡列表"`
}

type EnterpriseDeviceInfo struct {
	DeviceID     uint      `json:"device_id" description:"设备ID"`
	VirtualNo    string    `json:"virtual_no" description:"设备虚拟号"`
	DeviceName   string    `json:"device_name" description:"设备名称"`
	DeviceModel  string    `json:"device_model" description:"设备型号"`
	DeviceType   string    `json:"device_type" description:"设备类型"`
	AuthorizedAt time.Time `json:"authorized_at" description:"授权时间"`
}

type DeviceCardInfo struct {
	CardID            uint   `json:"card_id" description:"卡ID"`
	ICCID             string `json:"iccid" description:"ICCID"`
	MSISDN            string `json:"msisdn" description:"手机号"`
	CarrierName       string `json:"carrier_name" description:"运营商名称"`
	NetworkStatus     int    `json:"network_status" description:"网络状态：0=停机 1=开机"`
	NetworkStatusName string `json:"network_status_name" description:"网络状态名称"`
	GatewayExtend     string `json:"gateway_extend" description:"Gateway 卡状态扩展字段，原样返回上游 extend，用于展示运营商侧实际停机原因"`
}

type DeviceDetailReq struct {
	DeviceID uint `json:"-" params:"device_id" path:"device_id" validate:"required" required:"true" description:"设备ID"`
}

type DeviceCardOperationReq struct {
	DeviceID uint   `json:"-" params:"device_id" path:"device_id" validate:"required" required:"true" description:"设备ID"`
	CardID   uint   `json:"-" params:"card_id" path:"card_id" validate:"required" required:"true" description:"卡ID"`
	Reason   string `json:"reason" validate:"max=200" description:"操作原因"`
}

type DeviceCardOperationResp struct {
	Success bool   `json:"success" description:"操作是否成功"`
	Message string `json:"message" description:"操作结果消息"`
}
