package schema

// CompiledDoc is the schema for <stem>-compile.json.
//
// Static configuration is resolved and the tenant inventory is embedded.
type CompiledDoc struct {
	Namespace          string            `json:"namespace"`
	Region             string            `json:"region"`
	RetentionWindow    CompiledWindow    `json:"retentionWindow"`
	ShardStepInterval  string            `json:"shardStepInterval"`
	SourceReplicaCount int               `json:"sourceReplicaCount"`
	Steps              CompiledSteps     `json:"steps"`
	TargetReplicaCount int               `json:"targetReplicaCount"`
	Tenants            []string          `json:"tenants,omitempty"`
	Vmcluster          CompiledVmcluster `json:"vmcluster"`
	Vmctl              CompiledVmctl     `json:"vmctl"`
	Vmselects          CompiledVmselects `json:"vmselects"`
}

// CompiledWindow is the retentionWindow sub-object.
type CompiledWindow struct {
	End   string `json:"end"`
	Start string `json:"start"`
}

// CompiledSteps is the steps sub-object grouping stage items.
//
// Field declaration order is the JSON key order; stages are declared in
// workflow order.
type CompiledSteps struct {
	Prepare      CompiledStage `json:"prepare"`
	Migration    CompiledStage `json:"migration"`
	Decommission CompiledStage `json:"decommission"`
}

// CompiledStage is one stage's items list (prepare, migration, decommission).
type CompiledStage struct {
	Items []CompiledStep `json:"items"`
}

// CompiledStep is one entry in a stage's items list.
//
// Field declaration order is the JSON key order, matching plan.json's
// name → desc → command. Command and Desc use omitempty to match
// conditional-inclusion behavior.
type CompiledStep struct {
	Name    string   `json:"name"`
	Desc    string   `json:"desc,omitempty"`
	Command []string `json:"command,omitempty"`
}

// CompiledVmcluster is the vmcluster sub-object.
type CompiledVmcluster struct {
	Name               string `json:"name"`
	VminsertName       string `json:"vminsertName"`
	VminsertURLPattern string `json:"vminsertURLPattern"`
	VmselectName       string `json:"vmselectName"`
	VmselectURLPattern string `json:"vmselectURLPattern"`
}

// CompiledVmctl is the vmctl sub-object.
type CompiledVmctl struct {
	Concurrency    *int   `json:"concurrency"`
	RateLimitBytes *int   `json:"rateLimitBytes"`
	StepInterval   string `json:"stepInterval"`
}

// CompiledVmselects configures the two temporary vmselects: one shared
// image, one target sub-block per vmselect.
type CompiledVmselects struct {
	Image     string                 `json:"image"`
	Migration CompiledVmselectTarget `json:"migration"`
	Candidate CompiledVmselectTarget `json:"candidate"`
}

// CompiledVmselectTarget is one temporary vmselect's identity and sizing.
type CompiledVmselectTarget struct {
	Name       string            `json:"name"`
	URLPattern string            `json:"urlPattern"`
	Replicas   *int              `json:"replicas"`
	Resources  CompiledResources `json:"resources"`
}

// CompiledResources is the resources block inside a vmselects target.
type CompiledResources struct {
	Limits   CompiledResourceQuant `json:"limits"`
	Requests CompiledResourceQuant `json:"requests"`
}

// CompiledResourceQuant is one of {limits, requests} with cpu/memory.
type CompiledResourceQuant struct {
	CPU    *string `json:"cpu"`
	Memory *string `json:"memory"`
}
