package entity

import "time"

type ClusterConfigBackupPolicy struct {
	ID                  uint64
	ClusterID           uint64
	Enabled             bool
	IntervalSec         int32
	NextRunAt           *time.Time
	LastBackupAt        *time.Time
	LastSuccessAt       *time.Time
	LastError           string
	DeleteBackupPending bool
	DeletePolicyPending bool
}

type ClusterConfigBackup struct {
	ID                  uint64
	ClusterID           uint64
	SystemVariables     map[string]string
	PdConfig            map[string]any
	PdServerConfig      map[string]any
	PlacementRules      []PlacementRuleBundle
	StoreLimits         map[string]StoreLimits
	NewCollationEnabled *bool
	CapturedAt          time.Time
}

// PlacementRuleBundle represents a rule bundle with group configuration and rules
type PlacementRuleBundle struct {
	GroupID  string          `json:"group_id"`
	Index    int             `json:"group_index"`
	Override bool            `json:"group_override"`
	Rules    []PlacementRule `json:"rules"`
}

// PlacementRule represents a single placement rule
type PlacementRule struct {
	GroupID         string            `json:"group_id"`
	ID              string            `json:"id"`
	Index           int               `json:"index,omitempty"`
	Override        bool              `json:"override,omitempty"`
	StartKey        string            `json:"start_key,omitempty"`
	EndKey          string            `json:"end_key,omitempty"`
	Role            string            `json:"role"`
	Count           int               `json:"count"`
	LabelConstraint []LabelConstraint `json:"label_constraints,omitempty"`
	LocationLabels  []string          `json:"location_labels,omitempty"`
	IsolationLevel  string            `json:"isolation_level,omitempty"`
}

// LabelConstraint represents label constraint in placement rules
type LabelConstraint struct {
	Key    string   `json:"key"`
	Op     string   `json:"op"`
	Values []string `json:"values,omitempty"`
}

// StoreLimits represents the rate limits for store scheduling operations
type StoreLimits struct {
	AddPeer    int `json:"add-peer"`
	RemovePeer int `json:"remove-peer"`
}
