package jiracli

const (
	UserPasswordStrategyEmail  = "email"
	UserPasswordStrategyCustom = "custom"
	UserMFALevelDisable        = 0
	UserMFALevelEnable         = 1
	UserMFALevelForce          = 2

	AccountSecretTypeToken     = "token"
	AccountSecretTypePassword  = "password"
	AccountSecretTypeSSHKey    = "ssh_key"
	AccountSecretTypeAccessKey = "access_key"
	AccountSecretTypeAPIKey    = "api_key"

	AssetTypeKubernetes = "k8s"
	AssetTypeLinux      = "linux"

	ConnectMethodWebCli = "web_cli"
)

///////////////////
// entities
//////////////////

type EnumValue struct {
	// Value is the value of a enum.
	Value string `json:"value"`
	// Label is the description
	Label string `json:"label"`
}

type EnumValueInt struct {
	Value int `json:"value"`
	// Label is the description
	Label string `json:"label"`
}

type (
	UserPasswordStrategy EnumValue
	UserMFALevel         EnumValueInt

	AccountSecretType EnumValue

	AssetType EnumValue
)

type UserGroup struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type User struct {
	ID               string               `json:"id"`
	Name             string               `json:"name"`
	Username         string               `json:"username"`
	Email            string               `json:"email"`
	Groups           []UserGroup          `json:"groups"`
	MFALevel         UserMFALevel         `json:"mfa_level"`
	PasswordStrategy UserPasswordStrategy `json:"password_strategy"`
	IsActive         bool                 `json:"is_active"`
}

type Account struct {
	ID          string            `json:"id"`
	Name        string            `json:"name"`     // the name of this account
	Username    string            `json:"username"` // the username to use this account, not `User.Username`
	SecretType  AccountSecretType `json:"secret_type"`
	Secret      string            `json:"secret"` // only used when creating or updating
	HasSecret   bool              `json:"has_secret"`
	Asset       Asset             `json:"asset"`
	DateCreated string            `json:"date_created"` // Format: 2023/12/14 16:19:06 +0800
	DateUpdated string            `json:"date_updated"` // Format: 2023/12/14 16:19:06 +0800
}

type Asset struct {
	ID      string    `json:"id"`
	Name    string    `json:"name"`
	Address string    `json:"address"`
	Type    AssetType `json:"type"`
}

type ConnectionToken struct {
	ID          string `json:"id"`
	Value       string `json:"value"`
	DateExpired string `json:"date_expired"`
	DateCreated string `json:"date_created"`
	DateUpdated string `json:"date_updated"`
}

///////////////////
// requests
//////////////////

type CreateUserReq struct {
	Name             string               `json:"name"`
	Username         string               `json:"username"`
	Email            string               `json:"email"`
	Groups           []UserGroup          `json:"groups"`
	MFALevel         UserMFALevel         `json:"mfa_level"`
	PasswordStrategy UserPasswordStrategy `json:"password_strategy"`
	IsActive         bool                 `json:"is_active"`
}

type CreateAccountReq struct {
	Name       string            `json:"name"`     // the name of this account
	Username   string            `json:"username"` // the username to use this account, not `User.Username`
	SecretType AccountSecretType `json:"secret_type"`
	Asset      *Asset            `json:"asset,omitempty"`
}

type PatchAccountTokenReq struct {
	ID         string            `json:"id"`
	Name       string            `json:"name"`
	SecretType AccountSecretType `json:"secret_type"`
	Secret     string            `json:"secret"` // only used when creating or updating
}

type CreateConnectionTokenReq struct {
	UserID        string `json:"user"`
	AssetID       string `json:"asset"`
	Account       string `json:"account"`
	Protocol      string `json:"protocol"`
	InputUserName string `json:"input_username"`
	InputSecret   string `json:"input_secret"`
	ConnectMethod string `json:"connect_method"`
}

type GetRoleResp struct {
	ID          uint64      `json:"id"`
	Self        string      `json:"self"`
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Actors      []RoleActor `json:"actors"`
}

type RoleActor struct {
	ID          uint64 `json:"id"`
	DisplayName string `json:"displayName"`
	ActorType   string `json:"type"`
	Name        string `json:"name"`
	AvatarUrl   string `json:"avatarUrl"`
}

type UpdateRoleReq struct {
	CategorisedActors CategorisedActorsStruct `json:"categorisedActors"`
}

type UpdateRoleResp struct {
}

type CategorisedActorsStruct struct {
	AtlassianUserRoleActor []string `json:"atlassian-user-role-actor"`
}
