package server

import (
	"time"
)

// ClientConfig holds client authentication and quota information
type ClientConfig struct {
	ClientID     string `json:"client_id"`
	APIKey       string `json:"api_key"`
	MaxSizeBytes int64  `json:"max_size_bytes"`
	Dataset      string `json:"dataset"`
	Enabled      bool   `json:"enabled"`
	StorageType  string `json:"storage_type"` // "s3" or "local"
	// RotationPolicy defines the snapshot retention policy for this client
	// If set, the client must use this policy and cannot override it
	RotationPolicy *RotationPolicy `json:"rotation_policy,omitempty"`
}

// RotationPolicy defines retention settings for automatic snapshots.
// When set on the server, clients must use this policy for local rotation.
type RotationPolicy struct {
	// KeepHourly is the number of hourly snapshots to keep
	KeepHourly int `json:"keep_hourly"`
	// KeepDaily is the number of daily snapshots to keep
	KeepDaily int `json:"keep_daily"`
	// KeepWeekly is the number of weekly snapshots to keep
	KeepWeekly int `json:"keep_weekly"`
	// KeepMonthly is the number of monthly snapshots to keep
	KeepMonthly int `json:"keep_monthly"`
}

// SnapshotMetadata represents snapshot information
type SnapshotMetadata struct {
	ClientID     string    `json:"client_id"`
	SnapshotID   string    `json:"snapshot_id"`
	Timestamp    time.Time `json:"timestamp"`
	SizeBytes    int64     `json:"size_bytes"`
	DatasetName  string    `json:"dataset_name"`
	StorageKey   string    `json:"storage_key"`
	StorageType  string    `json:"storage_type"`
	Compressed   bool      `json:"compressed"`
	Incremental  bool      `json:"incremental"`
	BaseSnapshot string    `json:"base_snapshot,omitempty"`
}

// UploadRequest represents a snapshot upload request
type UploadRequest struct {
	ClientID      string `json:"client_id"`
	APIKey        string `json:"api_key"`
	DatasetName   string `json:"dataset_name"`
	Timestamp     string `json:"timestamp"`
	Compressed    bool   `json:"compressed"`
	EstimatedSize int64  `json:"estimated_size"`
	Incremental   bool   `json:"incremental"`
	BaseSnapshot  string `json:"base_snapshot,omitempty"`
}

// UploadResponse represents the response to an upload request
type UploadResponse struct {
	Success      bool   `json:"success"`
	Message      string `json:"message"`
	UploadURL    string `json:"upload_url,omitempty"`
	UploadMethod string `json:"upload_method,omitempty"` // "s3" or "zfs-receive"
	StorageKey   string `json:"storage_key,omitempty"`
}

// StatusResponse represents the response to a status request
type StatusResponse struct {
	Success        bool                `json:"success"`
	TotalSnapshots int                 `json:"total_snapshots"`
	UsedBytes      int64               `json:"used_bytes"`
	MaxBytes       int64               `json:"max_bytes"`
	PercentUsed    float64             `json:"percent_used"`
	Snapshots      []*SnapshotMetadata `json:"snapshots"`
	StorageType    string              `json:"storage_type"`
}

// RotationPolicyResponse represents the response to a rotation policy request
type RotationPolicyResponse struct {
	Success        bool            `json:"success"`
	Message        string          `json:"message,omitempty"`
	RotationPolicy *RotationPolicy `json:"rotation_policy,omitempty"`
	// ServerManaged indicates if the policy is managed by the server
	// If true, client must use this policy and cannot override it
	ServerManaged bool `json:"server_managed"`
}
