package store

import "time"

type Subscription struct {
	ID          int64      `json:"id"`
	Name        string     `json:"name"`
	URL         string     `json:"url"`
	Type        string     `json:"type"`
	IntervalSec int        `json:"interval_sec"`
	Enabled     bool       `json:"enabled"`
	LastFetchAt *time.Time `json:"last_fetch_at,omitempty"`
	LastError   string     `json:"last_error,omitempty"`
	NodeCount   int        `json:"node_count"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
}

type APIKey struct {
	ID         int64      `json:"id"`
	Name       string     `json:"name"`
	KeyPrefix  string     `json:"key_prefix"`
	Enabled    bool       `json:"enabled"`
	LastUsedAt *time.Time `json:"last_used_at,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
}

type ProxyNode struct {
	ID             int64      `json:"id"`
	SubscriptionID *int64     `json:"subscription_id,omitempty"`
	Name           string     `json:"name"`
	RuntimeName    string     `json:"runtime_name"`
	Type           string     `json:"type"`
	RawConfig      string     `json:"raw_config"`
	Source         string     `json:"source"`
	Enabled        bool       `json:"enabled"`
	Country        string     `json:"country"`
	LatencyMs      int        `json:"latency_ms"`
	Alive          bool       `json:"alive"`
	CheckedAt      *time.Time `json:"checked_at,omitempty"`
	CreatedAt      time.Time  `json:"created_at"`
	UpdatedAt      time.Time  `json:"updated_at"`
}

type Rule struct {
	ID             int64     `json:"id"`
	Priority       int       `json:"priority"`
	RuleType       string    `json:"rule_type"`
	Payload        string    `json:"payload"`
	Target         string    `json:"target"`
	Source         string    `json:"source"`
	SubscriptionID *int64    `json:"subscription_id,omitempty"`
	Enabled        bool      `json:"enabled"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

type ProxyGroup struct {
	ID             int64     `json:"id"`
	Name           string    `json:"name"`
	RuntimeName    string    `json:"runtime_name"`
	Type           string    `json:"type"`
	Proxies        string    `json:"proxies"`
	Source         string    `json:"source"`
	SubscriptionID *int64    `json:"subscription_id,omitempty"`
	Enabled        bool      `json:"enabled"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

type AuditLog struct {
	ID        int64     `json:"id"`
	Action    string    `json:"action"`
	Resource  string    `json:"resource"`
	Detail    string    `json:"detail"`
	CreatedAt time.Time `json:"created_at"`
}

type RequestLog struct {
	ID        int64     `json:"id"`
	Level     string    `json:"level"`
	Source    string    `json:"source"`
	Message   string    `json:"message"`
	CreatedAt time.Time `json:"created_at"`
}

type MergedRule struct {
	Priority int    `json:"priority"`
	Rule     string `json:"rule"`
	Source   string `json:"source"`
}

type ProxyRequestLog struct {
	ID           int64     `json:"id"`
	Host         string    `json:"host"`
	Network      string    `json:"network"`
	RuleType     string    `json:"rule_type"`
	RulePayload  string    `json:"rule_payload"`
	RuleLine     string    `json:"rule_line"`
	OutboundNode string    `json:"outbound_node"`
	OutboundChain string   `json:"outbound_chain"`
	Upload       int64     `json:"upload"`
	Download     int64     `json:"download"`
	Success      bool      `json:"success"`
	StartedAt    time.Time `json:"started_at"`
	EndedAt      time.Time `json:"ended_at"`
	CreatedAt    time.Time `json:"created_at"`
}
