package v1

import (
	"kami/internal/consts"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// ====================================================================================
// Cookie Account Management API
// ====================================================================================

type JdCookieAccountApi struct {
	CreateAccountReq  *CreateAccountReq       `path:"/jd-cookie/account/create"  method:"post" summary:"Create Cookie Account" tags:"JD Cookie Management"`
	BatchCreateReq    *BatchCreateReq         `path:"/jd-cookie/account/batch-create" method:"post" summary:"Batch Create Cookie Accounts" tags:"JD Cookie Management"`
	ListAccountReq    *ListAccountReq         `path:"/jd-cookie/account/list" method:"get" summary:"Query Cookie Account List" tags:"JD Cookie Management"`
	GetAccountReq     *GetAccountReq          `path:"/jd-cookie/account/get" method:"get" summary:"Get Single Cookie Account" tags:"JD Cookie Management"`
	UpdateAccountReq  *UpdateAccountReq       `path:"/jd-cookie/account/update" method:"put" summary:"Update Cookie Account" tags:"JD Cookie Management"`
	DeleteAccountReq  *DeleteAccountReq       `path:"/jd-cookie/account/delete" method:"delete" summary:"Delete Cookie Account" tags:"JD Cookie Management"`
	ValidateCookieReq *ValidateCookieReq      `path:"/jd-cookie/account/validate" method:"post" summary:"Validate Cookie" tags:"JD Cookie Management"`
	BatchValidateReq  *BatchValidateCookieReq `path:"/jd-cookie/account/batch-validate" method:"post" summary:"Batch Validate Cookies" tags:"JD Cookie Management"`
	DeleteInvalidReq  *DeleteInvalidReq       `path:"/jd-cookie/account/delete-invalid" method:"delete" summary:"Delete All Invalid Cookies" tags:"JD Cookie Management"`
}

// ====================================================================================
// Cookie Account Management Request/Response Structures
// ====================================================================================

// CreateAccountReq Create Cookie Account Request
type CreateAccountReq struct {
	g.Meta      `path:"/jd-cookie/account/create" method:"post" summary:"Create Cookie Account" tags:"JD Cookie Management"`
	CookieValue string `json:"cookieValue" v:"required#Cookie内容不能为空" dc:"Cookie内容"`
	AccountName string `json:"accountName" v:"required#Cookie名称不能为空" dc:"账户名称"`
	Remark      string `json:"remark" dc:"备注信息"`
}

type CreateAccountRes struct {
	g.Meta   `mime:"application/json"`
	CookieId string                `json:"cookieId" dc:"Cookie唯一标识"`
	Status   consts.JdCookieStatus `json:"status" dc:"账户状态"`
}

// BatchCreateReq Batch Create Cookie Account Request
type BatchCreateReq struct {
	g.Meta  `path:"/jd-cookie/account/batch-create" method:"post" summary:"Batch Create Cookie Accounts" tags:"JD Cookie Management"`
	Cookies []*CreateAccountReq `json:"cookies" v:"required#Cookie列表不能为空" dc:"Cookie列表"`
}

type BatchCreateRes struct {
	g.Meta      `mime:"application/json"`
	SuccessIds  []string             `json:"successIds" dc:"成功创建的Cookie ID列表"`
	FailedCount int                  `json:"failedCount" dc:"失败数量"`
	FailedItems []*BatchCreateResult `json:"failedItems" dc:"失败的Cookie详情"`
}

type BatchCreateResult struct {
	Index       int    `json:"index" dc:"在请求中的索引(从0开始)"`
	AccountName string `json:"accountName" dc:"账户名称"`
	ErrorMsg    string `json:"errorMsg" dc:"失败原因"`
}

// ListAccountReq Query Cookie Account List Request
type ListAccountReq struct {
	g.Meta  `path:"/jd-cookie/account/list" method:"get" summary:"Query Cookie Account List" tags:"JD Cookie Management"`
	Page    int                   `json:"page" d:"1" dc:"页码"`
	Size    int                   `json:"size" d:"20" dc:"每页大小"`
	Status  consts.JdCookieStatus `json:"status" dc:"状态筛选"`
	Keyword string                `json:"keyword" dc:"关键字搜索"`
}

type ListAccountRes struct {
	g.Meta `mime:"application/json"`
	List   []*CookieAccountInfo `json:"list" dc:"Cookie列表"`
	Total  int                  `json:"total" dc:"总数"`
}

// GetAccountReq Get Single Cookie Account Request
type GetAccountReq struct {
	g.Meta   `path:"/jd-cookie/account/get" method:"get" summary:"Get Single Cookie Account" tags:"JD Cookie Management"`
	CookieId string `json:"cookieId" v:"required#Cookie ID不能为空" dc:"Cookie ID"`
}

type GetAccountRes struct {
	g.Meta  `mime:"application/json"`
	Account *CookieAccountInfo `json:"account" dc:"Cookie账户信息"`
}

type CookieAccountInfo struct {
	Id           int64                 `json:"id" dc:"主键ID"`
	CookieId     string                `json:"cookieId" dc:"Cookie ID"`
	CookieValue  string                `json:"cookieValue" dc:"Cookie内容"`
	AccountName  string                `json:"accountName" dc:"账户名称"`
	Status       consts.JdCookieStatus `json:"status" dc:"状态：1正常 2暂停 3失效"`
	FailureCount int                   `json:"failureCount" dc:"连续失败次数"`
	LastUsedAt   *gtime.Time           `json:"lastUsedAt" dc:"最后使用时间"`
	SuspendUntil *gtime.Time           `json:"suspendUntil" dc:"暂停解除时间"`
	CreatedAt    *gtime.Time           `json:"createdAt" dc:"创建时间"`
	UpdatedAt    *gtime.Time           `json:"updatedAt" dc:"更新时间"`
	DeletedAt    *gtime.Time           `json:"deletedAt" dc:"删除时间"`
	Remark       string                `json:"remark" dc:"备注信息"`
}

// UpdateAccountReq Update Cookie Account Request
type UpdateAccountReq struct {
	g.Meta      `path:"/jd-cookie/account/update" method:"put" summary:"Update Cookie Account" tags:"JD Cookie Management"`
	CookieId    string                `json:"cookieId" v:"required#Cookie ID不能为空" dc:"Cookie ID"`
	CookieValue string                `json:"cookieValue" dc:"Cookie内容"`
	AccountName string                `json:"accountName" dc:"账户名称"`
	Status      consts.JdCookieStatus `json:"status" v:"required-without:1,2,3#状态值无效，有效值为:1(正常),2(暂停),3(失效)" dc:"状态"`
	Remark      string                `json:"remark" dc:"备注信息"`
}

type UpdateAccountRes struct {
	g.Meta `mime:"application/json"`
}

// DeleteAccountReq Delete Cookie Account Request
type DeleteAccountReq struct {
	g.Meta   `path:"/jd-cookie/account/delete" method:"delete" summary:"Delete Cookie Account" tags:"JD Cookie Management"`
	CookieId string `json:"cookieId" v:"required#Cookie ID不能为空" dc:"Cookie ID"`
}

type DeleteAccountRes struct {
	g.Meta `mime:"application/json"`
}

type CookieCheckResult struct {
	CookieId string                `json:"cookieId" dc:"Cookie ID"`
	Status   consts.JdCookieStatus `json:"status" dc:"状态"`
	Message  string                `json:"message" dc:"检测信息"`
}

// DeleteInvalidReq Delete All Invalid Cookies Request
type DeleteInvalidReq struct {
	g.Meta `path:"/jd-cookie/account/delete-invalid" method:"delete" summary:"Delete All Invalid Cookies" tags:"JD Cookie Management"`
}

type DeleteInvalidRes struct {
	g.Meta       `mime:"application/json"`
	DeletedCount int                   `json:"deletedCount" dc:"删除的Cookie数量"`
	SuccessIds   []string              `json:"successIds" dc:"成功删除的Cookie ID列表"`
	FailedCount  int                   `json:"failedCount" dc:"删除失败的数量"`
	Results      []*CookieDeleteResult `json:"results" dc:"删除结果详情"`
}

type CookieDeleteResult struct {
	CookieId string `json:"cookieId" dc:"Cookie ID"`
	Success  bool   `json:"success" dc:"是否删除成功"`
	Message  string `json:"message" dc:"删除结果信息"`
}

// ValidateCookieReq Validate Cookie Request
type ValidateCookieReq struct {
	g.Meta      `path:"/jd-cookie/account/validate" method:"post" summary:"Validate Cookie" tags:"JD Cookie Management"`
	CookieValue string `json:"cookieValue" v:"required#Cookie内容不能为空" dc:"Cookie内容"`
}

type ValidateCookieRes struct {
	g.Meta   `mime:"application/json"`
	IsValid  bool   `json:"isValid" dc:"Cookie是否有效"`
	Message  string `json:"message" dc:"验证结果信息"`
	CookieId string `json:"cookieId" dc:"Cookie唯一标识(仅当Cookie有效时返回)"`
}

// BatchValidateCookieReq Batch Validate Cookies Request
type BatchValidateCookieReq struct {
	g.Meta  `path:"/jd-cookie/account/batch-validate" method:"post" summary:"Batch Validate Cookies" tags:"JD Cookie Management"`
	Cookies []*ValidateCookieItem `json:"cookies" v:"required#Cookie列表不能为空" dc:"Cookie列表"`
}

type ValidateCookieItem struct {
	Index       int    `json:"index" dc:"在请求中的索引(从0开始)"`
	CookieValue string `json:"cookieValue" v:"required#Cookie内容不能为空" dc:"Cookie内容"`
	AccountName string `json:"accountName" dc:"账户名称(可选，用于日志记录)"`
}

type BatchValidateCookieRes struct {
	g.Meta       `mime:"application/json"`
	TotalCount   int                    `json:"totalCount" dc:"总数量"`
	ValidCount   int                    `json:"validCount" dc:"有效数量"`
	InvalidCount int                    `json:"invalidCount" dc:"无效数量"`
	Results      []*BatchValidateResult `json:"results" dc:"验证结果详情"`
}

type BatchValidateResult struct {
	Index       int    `json:"index" dc:"在请求中的索引(从0开始)"`
	AccountName string `json:"accountName" dc:"账户名称"`
	IsValid     bool   `json:"isValid" dc:"Cookie是否有效"`
	Message     string `json:"message" dc:"验证结果信息"`
	CookieId    string `json:"cookieId" dc:"Cookie唯一标识(仅当Cookie有效时返回)"`
}
