package apikey

import (
	"time"

	"github.com/tidbcloud/account/internel/svc/comsvc"
)

type ChangeApiKeyRefResourceRoleParam struct {
	ApiKeyId   uint64
	ScopeType  string
	ResourceId uint64
	NewRole    string
}

type CheckApiKeyBelongToResourceParam struct {
	ScopeType  string
	ResourceId uint64
	ApiKeyId   uint64
}

type CreateApiKeyParam struct {
	Source       string
	Description  string
	ScopeType    string
	ResourceIds  []uint64
	Role         string
	Operator     string
	OperatorType int32
	RateLimitRpm uint32
	IgnoreDBuser bool
	ExpiredAt    *time.Time
	BizAttr      string
	Type         string
}

type ApiKey struct {
	Id            uint64
	AccessKey     string
	SecretKey     string
	Source        string
	Description   string
	CreatedBy     string
	UpdatedBy     string
	CreatedAt     *time.Time
	UpdatedAt     *time.Time
	ResourceInfos []*ApiKeyResourceInfo
	RateLimitRpm  uint32
	ExpiredAt     *time.Time
	BizAttr       string
	Type          string
}

type ApiKeys struct {
	Total int32
	Items []*ApiKey
}

type ApiKeyResourceInfo struct {
	ScopeType  string
	ResourceId uint64
	Role       string
	RoleId     uint64
}

type ApiKeyResourceInfos struct {
	Total int32
	Items []*ApiKeyResourceInfo
}

type UpdateApiKeyParam struct {
	ApiKeyId     uint64
	Description  string
	Operator     string
	OperatorType int32
	RateLimitRpm uint32
	ExpiredAt    *time.Time
	BizAttr      string
	ScopeType    string
	ResourceIds  []uint64
	Role         string
}

type DeleteApiKeyParam struct {
	ApiKeyId uint64
}

type BatchSetApiKeyExpireTimeParam struct {
	ApiKeyIds []uint64
	ExpiredAt *time.Time
}

type GrantApiKeyParam struct {
	ApiKeyId     uint64
	ScopeType    string
	ResourceIds  []uint64
	Role         string
	Operator     string
	OperatorType int32
	IgnoreDBuser bool
}

type RecoverApiKeyParam struct {
	ApiKeyId     uint64
	ScopeType    string
	ResourceId   uint64
	Role         string
	Operator     string
	OperatorType int32
}

type GetResourceInfoByApiKeyIDParam struct {
	ApiKeyId uint64
	PageNo   uint32
	PageSize uint32
}

type ListKeysByResourceIDParam struct {
	ScopeType   string
	ResourceId  uint64
	PageNo      uint32
	PageSize    uint32
	ApiKeyTypes []string
	AccessKey   string
	Desc        string
	Roles       []string
}

type AuthnApiKeyRet struct {
	AuthRet       bool
	Message       string
	ResourceInfos []AuthnApiKeyResourceInfo
}

type AuthnApiKeyResourceInfo struct {
	ScopeType  string `json:"scope_type"`
	ResourceID uint64 `json:"resource_id"`
	Role       string `json:"role"`
	RoleID     uint64 `json:"role_id"`
}

type ApiKeyAttr struct {
	Source       string
	Type         string
	Description  string
	RateLimitRpm uint32
	ExpiredAt    *time.Time
	BizAttr      string
}

type CreateOneConsoleApiKeyParam struct {
	Attrs           *ApiKeyAttr
	AssignRoleParam *comsvc.AssignIdentRolesParam
	RecAuditLog     bool
}

type UpdateOneConsoleApiKeyParam struct {
	KeyID           uint64
	Attrs           *ApiKeyAttr
	AssignRoleParam *comsvc.AssignIdentRolesParam
	RecAuditLog     bool
	AuditLogOrgID   uint64
}

type ListApiKeysParam struct {
	Type         string
	KeyLike      string
	OrgId        uint64
	OrgRoles     []string
	ProjectId    uint64
	ProjectRoles []string
	ClusterId    uint64
	ClusterRoles []string
	Page         uint32
	PerPage      uint32
}

type OneConsoleApiKey struct {
	Id           uint64
	AccessKey    string
	SecretKey    string
	Description  string
	CreatedBy    string
	UpdatedBy    string
	CreatedAt    *time.Time
	UpdatedAt    *time.Time
	OrgRole      *ApiKeyResourceInfo
	ProjectRoles []ApiKeyResourceInfo
	ClusterRoles []ApiKeyResourceInfo
}
