package api

import (
	"context"
	"errors"
)

var ErrNotFound = errors.New("agent not found")

type AgentControlAPI interface {
	CreateK8sAgent(ctx context.Context, req *CreateK8sAgentRequest) (*CreateK8sAgentResponse, error)
	DeleteK8sAgent(ctx context.Context, req *DeleteK8sAgentRequest) (*DeleteK8sAgentResponse, error)
	ListK8sAgents(ctx context.Context, req *ListK8sAgentsRequest) (*ListK8sAgentsResponse, error)
	GetK8sAgent(ctx context.Context, req *GetK8sAgentRequest) (*GetK8sAgentResponse, error)
	CreateTiDBAgent(ctx context.Context, req *CreateTiDBAgentRequest) (*CreateTiDBAgentResponse, error)
	DeleteTiDBAgent(ctx context.Context, req *DeleteTiDBAgentRequest) (*DeleteTiDBAgentResponse, error)
	ListTiDBAgents(ctx context.Context, req *ListTiDBAgentsRequest) (*ListTiDBAgentsResponse, error)
	GetTiDBAgent(ctx context.Context, req *GetTiDBAgentRequest) (*GetTiDBAgentResponse, error)
	PauseTiDBAgent(ctx context.Context, req *PauseTiDBAgentRequest) (*PauseTiDBAgentResponse, error)
	ResumeTiDBAgent(ctx context.Context, req *ResumeTiDBAgentRequest) (*ResumeTiDBAgentResponse, error)
	ScaleTiDBAgent(ctx context.Context, req *ScaleTiDBAgentRequest) (*ScaleTiDBAgentResponse, error)
}

type CreateK8sAgentRequest struct {
	TenantID  string          `json:"tenantID"`
	ProjectID string          `json:"projectID"`
	Dataplane DataplaneConfig `json:"dataplane"`
}

type CreateK8sAgentResponse struct{}

type DeleteK8sAgentRequest struct {
	ProjectID string `json:"projectID"`
}

type DeleteK8sAgentResponse struct{}

type ListK8sAgentsRequest struct{}

type ListK8sAgentsResponse struct{}

type GetK8sAgentRequest struct {
	ProjectID string `json:"projectID"`
}

type GetK8sAgentResponse struct {
	ProjectID             string `json:"projectID"`
	TenantID              string `json:"tenantID"`
	KubernetesClusterName string `json:"kubernetesClusterName"`
	Phase                 string `json:"phase"`
	Deleting              bool   `json:"deleting"`
}

type CreateTiDBAgentRequest struct {
	TenantID  string            `json:"tenantID"`
	ProjectID string            `json:"projectID"`
	ClusterID string            `json:"clusterID"`
	Dataplane DataplaneConfig   `json:"dataplane"`
	TiDB      TiDBClusterConfig `json:"tidb"`
}

type CreateTiDBAgentResponse struct{}

type DeleteTiDBAgentRequest struct {
	ClusterID string `json:"clusterID"`
}

type DeleteTiDBAgentResponse struct{}

type ListTiDBAgentsRequest struct{}

type ListTiDBAgentsResponse struct{}

type GetTiDBAgentRequest struct {
	ClusterID string `json:"clusterID"`
}

type GetTiDBAgentResponse struct{}

type PauseTiDBAgentRequest struct {
	ClusterID string `json:"clusterID"`
}

type PauseTiDBAgentResponse struct{}

type ResumeTiDBAgentRequest struct {
	ClusterID string `json:"clusterID"`
}

type ResumeTiDBAgentResponse struct{}

type ScaleTiDBAgentRequest struct {
	ClusterID string `json:"clusterID"`
}

type ScaleTiDBAgentResponse struct{}

type DataplaneConfig struct {
	ClusterName string       `json:"clusterName"`
	AWS         *AWSConfig   `json:"aws,omitempty"`
	GCP         *GCPConfig   `json:"gcp,omitempty"`
	Azure       *AzureConfig `json:"azure,omitempty"`
}

type AWSConfig struct {
	VpcID              string   `json:"vpcID"`
	AccountID          string   `json:"accountID"`
	NodeSubnetIDs      []string `json:"nodeSubnetIDs"`
	SecurityGroupID    string   `json:"securityGroupID"`
	AssumeRoleArn      string   `json:"assumeRoleArn"`
	ProviderConfigName string   `json:"providerConfigName"`
}

type GCPConfig struct {
	Network string   `json:"network"`
	Project string   `json:"project"`
	Subnets []string `json:"subnets"`
}

type AzureConfig struct {
	Network            string `json:"network"`
	SubscriptionID     string `json:"subscriptionID"`
	SubnetID           string `json:"subnetID"`
	PodSubnetID        string `json:"podSubnetID,omitempty"`
	ResourceGroup      string `json:"resourceGroup"`
	ProviderConfigName string `json:"providerConfigName"`
}

type TiDBClusterConfig struct {
	Version  string              `json:"version"`
	Topology TiDBClusterTopology `json:"topology"`
}

type TiDBClusterTopology struct {
	TiDB    TiDB    `json:"tidb"`
	PD      PD      `json:"pd"`
	TiKV    TiKV    `json:"tikv"`
	TiFlash TiFlash `json:"tiflash"`
}

type TiDB struct {
	Replicas int `json:"replicas"`
}

type PD struct {
	Replicas int `json:"replicas"`
}

type TiKV struct {
	Replicas int `json:"replicas"`
}

type TiFlash struct {
	Replicas int `json:"replicas"`
}
