package platform

type Page[T any] struct {
	Items  []T `json:"items"`
	Total  int `json:"total"`
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
}

type MonitorSummary struct {
	TotalVehicles      int    `json:"totalVehicles"`
	LocationVehicles   int    `json:"locationVehicles"`
	NoLocationVehicles int    `json:"noLocationVehicles"`
	OnlineVehicles     int    `json:"onlineVehicles"`
	OfflineVehicles    int    `json:"offlineVehicles"`
	DrivingVehicles    int    `json:"drivingVehicles"`
	IdleVehicles       int    `json:"idleVehicles"`
	AlertVehicles      int    `json:"alertVehicles"`
	UnknownVehicles    int    `json:"unknownVehicles"`
	ActiveToday        int    `json:"activeToday"`
	FrameToday         int    `json:"frameToday"`
	AlertDataAvailable bool   `json:"alertDataAvailable"`
	Truncated          bool   `json:"truncated"`
	AsOf               string `json:"asOf"`
}

type MonitorMapResponse struct {
	Mode      string              `json:"mode"`
	Zoom      int                 `json:"zoom"`
	Total     int                 `json:"total"`
	Truncated bool                `json:"truncated"`
	Points    []MonitorMapPoint   `json:"points"`
	Clusters  []MonitorMapCluster `json:"clusters"`
	AsOf      string              `json:"asOf"`
}

type MonitorWorkspaceResponse struct {
	Summary  MonitorSummary           `json:"summary"`
	Vehicles Page[VehicleRealtimeRow] `json:"vehicles"`
	Map      MonitorMapResponse       `json:"map"`
}

type MonitorMapPoint struct {
	VIN              string   `json:"vin"`
	Plate            string   `json:"plate"`
	Protocol         string   `json:"protocol"`
	Protocols        []string `json:"protocols"`
	Longitude        float64  `json:"longitude"`
	Latitude         float64  `json:"latitude"`
	SpeedKmh         float64  `json:"speedKmh"`
	SOCPercent       float64  `json:"socPercent"`
	TotalMileageKm   float64  `json:"totalMileageKm"`
	LastSeen         string   `json:"lastSeen"`
	ReportIntervalMs *int64   `json:"reportIntervalMs,omitempty"`
	LocationSource   string   `json:"locationSource"`
	LocationConflict bool     `json:"locationConflict"`
	Status           string   `json:"status"`
}

type MonitorMapCluster struct {
	ID        string  `json:"id"`
	Longitude float64 `json:"longitude"`
	Latitude  float64 `json:"latitude"`
	Count     int     `json:"count"`
	Online    int     `json:"online"`
	Offline   int     `json:"offline"`
	Driving   int     `json:"driving"`
	Idle      int     `json:"idle"`
	Unknown   int     `json:"unknown"`
}

type TrackPlaybackResponse struct {
	VIN       string                `json:"vin"`
	Plate     string                `json:"plate"`
	Points    []HistoryLocationRow  `json:"points"`
	Events    []TrackPlaybackEvent  `json:"events"`
	Sources   []TrackPlaybackSource `json:"sources"`
	Segments  []TrackSegment        `json:"segments"`
	Stops     []TrackStop           `json:"stops"`
	Summary   TrackPlaybackSummary  `json:"summary"`
	Coverage  TrackCoverage         `json:"coverage"`
	Quality   TrackQuality          `json:"quality"`
	Total     int                   `json:"total"`
	Truncated bool                  `json:"truncated"`
	Sampled   bool                  `json:"sampled"`
	AsOf      string                `json:"asOf"`
}

type TrackPlaybackSummary struct {
	StartTime       string  `json:"startTime"`
	EndTime         string  `json:"endTime"`
	DistanceKm      float64 `json:"distanceKm"`
	DurationSeconds int64   `json:"durationSeconds"`
	AverageSpeedKmh float64 `json:"averageSpeedKmh"`
	MaximumSpeedKmh float64 `json:"maximumSpeedKmh"`
	PointCount      int     `json:"pointCount"`
	MovingSeconds   int64   `json:"movingSeconds"`
	StoppedSeconds  int64   `json:"stoppedSeconds"`
	StopCount       int     `json:"stopCount"`
	SegmentCount    int     `json:"segmentCount"`
}

type TrackPlaybackEvent struct {
	Index        int     `json:"index"`
	SampledIndex int     `json:"sampledIndex"`
	Type         string  `json:"type"`
	Title        string  `json:"title"`
	Time         string  `json:"time"`
	SpeedKmh     float64 `json:"speedKmh"`
	SOCPercent   float64 `json:"socPercent"`
	SOCAvailable bool    `json:"socAvailable"`
	DirectionDeg *int64  `json:"directionDeg,omitempty"`
	AlarmFlag    *int64  `json:"alarmFlag,omitempty"`
	Longitude    float64 `json:"longitude"`
	Latitude     float64 `json:"latitude"`
}

type TrackPlaybackSource struct {
	Protocol   string `json:"protocol"`
	PointCount int    `json:"pointCount"`
	StartTime  string `json:"startTime"`
	EndTime    string `json:"endTime"`
}

// TrackCoverage makes a bounded replay query explicit. Complete=false means
// summaries describe only the fetched slice, never the whole requested range.
type TrackCoverage struct {
	RequestedStart  string   `json:"requestedStart"`
	RequestedEnd    string   `json:"requestedEnd"`
	ActualStart     string   `json:"actualStart"`
	ActualEnd       string   `json:"actualEnd"`
	TotalPoints     int      `json:"totalPoints"`
	FetchedPoints   int      `json:"fetchedPoints"`
	ProcessedPoints int      `json:"processedPoints"`
	ReturnedPoints  int      `json:"returnedPoints"`
	Complete        bool     `json:"complete"`
	LimitReasons    []string `json:"limitReasons"`
	Evidence        string   `json:"evidence"`
}

// TrackSegment is inferred from GPS movement and gaps. It deliberately does
// not claim ignition state because vehicle_locations does not contain it.
type TrackSegment struct {
	Index             int     `json:"index"`
	Type              string  `json:"type"`
	Title             string  `json:"title"`
	StartTime         string  `json:"startTime"`
	EndTime           string  `json:"endTime"`
	DurationSeconds   int64   `json:"durationSeconds"`
	DistanceKm        float64 `json:"distanceKm"`
	PointCount        int     `json:"pointCount"`
	StartIndex        int     `json:"startIndex"`
	EndIndex          int     `json:"endIndex"`
	SampledStartIndex int     `json:"sampledStartIndex"`
	SampledEndIndex   int     `json:"sampledEndIndex"`
}

type TrackStop struct {
	Index           int     `json:"index"`
	StartTime       string  `json:"startTime"`
	EndTime         string  `json:"endTime"`
	DurationSeconds int64   `json:"durationSeconds"`
	PointCount      int     `json:"pointCount"`
	Longitude       float64 `json:"longitude"`
	Latitude        float64 `json:"latitude"`
	SampledIndex    int     `json:"sampledIndex"`
	Evidence        string  `json:"evidence"`
	startIndex      int
	endIndex        int
}

type TrackQuality struct {
	Status                  string `json:"status"`
	SelectedProtocol        string `json:"selectedProtocol"`
	RawPoints               int    `json:"rawPoints"`
	ValidPoints             int    `json:"validPoints"`
	AlternateSourcePoints   int    `json:"alternateSourcePoints"`
	InvalidCoordinatePoints int    `json:"invalidCoordinatePoints"`
	DuplicatePoints         int    `json:"duplicatePoints"`
	DriftPoints             int    `json:"driftPoints"`
	SourceSwitches          int    `json:"sourceSwitches"`
	LargeGapCount           int    `json:"largeGapCount"`
	MaximumGapSeconds       int64  `json:"maximumGapSeconds"`
	Evidence                string `json:"evidence"`
}

type HistoryMetricCatalog struct {
	Categories []HistoryDataCategory     `json:"categories"`
	Metrics    []HistoryMetricDefinition `json:"metrics"`
}

type MetricCatalog struct {
	Metrics []MetricDefinition `json:"metrics"`
	AsOf    string             `json:"asOf"`
}

type MetricDefinition struct {
	Key          string            `json:"key"`
	Label        string            `json:"label"`
	Description  string            `json:"description"`
	Unit         string            `json:"unit"`
	Category     string            `json:"category"`
	ValueType    string            `json:"valueType"`
	Protocols    []string          `json:"protocols"`
	SourceFields map[string]string `json:"sourceFields"`
	Searchable   bool              `json:"searchable"`
	Chartable    bool              `json:"chartable"`
	Alertable    bool              `json:"alertable"`
}

type HistoryDataCategory struct {
	Key   string `json:"key"`
	Label string `json:"label"`
}

type HistoryMetricDefinition struct {
	Key            string `json:"key"`
	Label          string `json:"label"`
	Unit           string `json:"unit"`
	Category       string `json:"category"`
	ValueType      string `json:"valueType"`
	DefaultVisible bool   `json:"defaultVisible"`
}

type HistoryDataResponse struct {
	Category string                    `json:"category"`
	Columns  []HistoryMetricDefinition `json:"columns"`
	Rows     []HistoryDataRow          `json:"rows"`
	Summary  HistoryDataSummary        `json:"summary"`
	Total    int                       `json:"total"`
	Limit    int                       `json:"limit"`
	Offset   int                       `json:"offset"`
	AsOf     string                    `json:"asOf"`
}

type HistoryDataSummary struct {
	ResultRows    int      `json:"resultRows"`
	VehicleCount  int      `json:"vehicleCount"`
	Sources       []string `json:"sources"`
	QueryDuration int64    `json:"queryDurationMs"`
}

type HistoryDataRow struct {
	ID            string         `json:"id"`
	VIN           string         `json:"vin"`
	Plate         string         `json:"plate"`
	Protocol      string         `json:"protocol"`
	DeviceTime    string         `json:"deviceTime"`
	ServerTime    string         `json:"serverTime"`
	Quality       string         `json:"quality"`
	QualityReason string         `json:"qualityReason"`
	EvidenceID    string         `json:"evidenceId,omitempty"`
	Values        map[string]any `json:"values"`
}

type HistorySeriesResponse struct {
	Metrics  []HistoryMetricDefinition `json:"metrics"`
	Series   []HistorySeries           `json:"series"`
	Summary  HistorySeriesSummary      `json:"summary"`
	DateFrom string                    `json:"dateFrom"`
	DateTo   string                    `json:"dateTo"`
	AsOf     string                    `json:"asOf"`
}

type HistorySeries struct {
	VIN         string               `json:"vin"`
	Plate       string               `json:"plate"`
	Protocol    string               `json:"protocol"`
	Metric      string               `json:"metric"`
	Label       string               `json:"label"`
	Unit        string               `json:"unit"`
	Aggregation string               `json:"aggregation"`
	Points      []HistorySeriesPoint `json:"points"`
}

type HistorySeriesPoint struct {
	Time  string   `json:"time"`
	Value *float64 `json:"value"`
	Min   *float64 `json:"min"`
	Max   *float64 `json:"max"`
	Count int64    `json:"count"`
}

type HistorySeriesSummary struct {
	RawPointCount       int64  `json:"rawPointCount"`
	BucketCount         int    `json:"bucketCount"`
	ReturnedPointCount  int    `json:"returnedPointCount"`
	SeriesCount         int    `json:"seriesCount"`
	GrainSeconds        int    `json:"grainSeconds"`
	TargetPoints        int    `json:"targetPoints"`
	ExpectedBucketCount int    `json:"expectedBucketCount"`
	MissingBucketCount  int    `json:"missingBucketCount"`
	QueryDuration       int64  `json:"queryDurationMs"`
	Complete            bool   `json:"complete"`
	Evidence            string `json:"evidence"`
}

type HistoryLocationSeriesQuery struct {
	VIN          string
	Protocol     string
	DateFrom     string
	DateTo       string
	GrainSeconds int
}

type HistoryLocationSeriesBucket struct {
	Time           string
	Protocol       string
	Count          int64
	SpeedAverage   *float64
	SpeedMinimum   *float64
	SpeedMaximum   *float64
	SpeedLast      *float64
	MileageAverage *float64
	MileageMinimum *float64
	MileageMaximum *float64
	MileageLast    *float64
}

type HistoryExportRequest struct {
	Keywords []string `json:"keywords"`
	Category string   `json:"category"`
	Protocol string   `json:"protocol"`
	DateFrom string   `json:"dateFrom"`
	DateTo   string   `json:"dateTo"`
	Metrics  []string `json:"metrics"`
	Format   string   `json:"format"`
}

type HistoryExportVehicleScope struct {
	VIN      string `json:"vin"`
	DateFrom string `json:"dateFrom"`
	DateTo   string `json:"dateTo"`
}

type HistoryExportJob struct {
	ID             string                      `json:"id"`
	Name           string                      `json:"name"`
	Status         string                      `json:"status"`
	Progress       int                         `json:"progress"`
	Format         string                      `json:"format"`
	Category       string                      `json:"category"`
	Protocol       string                      `json:"protocol,omitempty"`
	Keywords       []string                    `json:"keywords"`
	Metrics        []string                    `json:"metrics,omitempty"`
	VehicleVINs    []string                    `json:"vehicleVins"`
	VehicleScopes  []HistoryExportVehicleScope `json:"vehicleScopes"`
	DateFrom       string                      `json:"dateFrom"`
	DateTo         string                      `json:"dateTo"`
	OwnerID        string                      `json:"ownerId"`
	OwnerSubjectID string                      `json:"ownerSubjectId,omitempty"`
	OwnerName      string                      `json:"ownerName"`
	OwnerUsername  string                      `json:"ownerUsername"`
	OwnerRole      string                      `json:"ownerRole"`
	OwnerUserType  string                      `json:"ownerUserType"`
	AuthProvider   string                      `json:"authProvider"`
	CustomerRef    string                      `json:"customerRef,omitempty"`
	TenantRef      string                      `json:"tenantRef,omitempty"`
	RowCount       int                         `json:"rowCount"`
	TotalRows      int64                       `json:"totalRows"`
	ProcessedRows  int64                       `json:"processedRows"`
	FileSizeBytes  int64                       `json:"fileSizeBytes"`
	Error          string                      `json:"error,omitempty"`
	DownloadURL    string                      `json:"downloadUrl,omitempty"`
	CreatedAt      string                      `json:"createdAt"`
	UpdatedAt      string                      `json:"updatedAt"`
	CompletedAt    string                      `json:"completedAt,omitempty"`
	Evidence       string                      `json:"evidence"`
	filePath       string
}

type HistoryExportStoreQuery struct {
	Category string
	VIN      string
	Protocol string
	DateFrom string
	DateTo   string
	Metrics  []string
}

type HistoryExportCursor struct {
	Time     string
	Protocol string
	ID       string
	Offset   int
}

type AccessQuery struct {
	Keyword         string `json:"keyword"`
	Protocol        string `json:"protocol"`
	OEM             string `json:"oem"`
	Model           string `json:"model"`
	Provider        string `json:"provider"`
	FirstSeenFrom   string `json:"firstSeenFrom"`
	FirstSeenTo     string `json:"firstSeenTo"`
	LatestSeenFrom  string `json:"latestSeenFrom"`
	LatestSeenTo    string `json:"latestSeenTo"`
	OnlineState     string `json:"onlineState"`
	DelayState      string `json:"delayState"`
	ConnectionState string `json:"connectionState"`
	Limit           int    `json:"limit"`
	Offset          int    `json:"offset"`
}

type AccessEvidenceRow struct {
	VIN                 string
	Plate               string
	OEM                 string
	Model               string
	Company             string
	Protocol            string
	Provider            string
	Source              string
	FirstSeenAt         string
	LatestEventAt       string
	LatestReceivedAt    string
	LatestUpdatedAt     string
	ReportIntervalSec   *int
	LatestMessageType   string
	LatestEventID       string
	LatestError         string
	FirstSeenEvidence   string
	FirstSeenSource     string
	ReportIntervalProof string
	ReportSampleCount   int64
	Longitude           float64
	Latitude            float64
	SpeedKmh            float64
	SOCPercent          float64
	TotalMileageKm      float64
	DailyMileageKm      float64
}

type AccessVehicleRow struct {
	VIN                 string                 `json:"vin"`
	Plate               string                 `json:"plate"`
	OEM                 string                 `json:"oem"`
	Model               string                 `json:"model"`
	Company             string                 `json:"company"`
	Protocol            string                 `json:"protocol"`
	Provider            string                 `json:"provider"`
	Source              string                 `json:"source"`
	FirstSeenAt         string                 `json:"firstSeenAt"`
	LatestEventAt       string                 `json:"latestEventAt"`
	LatestReceivedAt    string                 `json:"latestReceivedAt"`
	ReportIntervalSec   *int                   `json:"reportIntervalSec"`
	DataDelaySec        *int                   `json:"dataDelaySec"`
	FreshnessSec        *int                   `json:"freshnessSec"`
	OnlineState         string                 `json:"onlineState"`
	ThresholdSec        int                    `json:"thresholdSec"`
	LatestMessageType   string                 `json:"latestMessageType"`
	LatestEventID       string                 `json:"latestEventId"`
	LatestError         string                 `json:"latestError"`
	DelayAbnormal       bool                   `json:"delayAbnormal"`
	FirstSeenEvidence   string                 `json:"firstSeenEvidence"`
	FirstSeenSource     string                 `json:"firstSeenSource"`
	ReportIntervalProof string                 `json:"reportIntervalEvidence"`
	ReportSampleCount   int64                  `json:"reportSampleCount"`
	ExpectedProtocols   []string               `json:"expectedProtocols"`
	ActualProtocols     []string               `json:"actualProtocols"`
	MissingProtocols    []string               `json:"missingProtocols"`
	ProtocolStatuses    []AccessProtocolStatus `json:"protocolStatuses"`
	ConnectionState     string                 `json:"connectionState"`
	ExpectationEvidence string                 `json:"expectationEvidence"`
}

type AccessProtocolStatus struct {
	Protocol               string  `json:"protocol"`
	Expected               bool    `json:"expected"`
	Connected              bool    `json:"connected"`
	Provider               string  `json:"provider"`
	FirstSeenAt            string  `json:"firstSeenAt"`
	LatestEventAt          string  `json:"latestEventAt"`
	LatestReceivedAt       string  `json:"latestReceivedAt"`
	ReportIntervalSec      *int    `json:"reportIntervalSec"`
	DataDelaySec           *int    `json:"dataDelaySec"`
	FreshnessSec           *int    `json:"freshnessSec"`
	OnlineState            string  `json:"onlineState"`
	ThresholdSec           int     `json:"thresholdSec"`
	DelayAbnormal          bool    `json:"delayAbnormal"`
	FirstSeenEvidence      string  `json:"firstSeenEvidence"`
	ReportIntervalEvidence string  `json:"reportIntervalEvidence"`
	Longitude              float64 `json:"longitude"`
	Latitude               float64 `json:"latitude"`
	SpeedKmh               float64 `json:"speedKmh"`
	SOCPercent             float64 `json:"socPercent"`
	TotalMileageKm         float64 `json:"totalMileageKm"`
	DailyMileageKm         float64 `json:"dailyMileageKm"`
}

type AccessUnresolvedIdentityQuery struct {
	Keyword  string `json:"keyword"`
	Protocol string `json:"protocol"`
	Limit    int    `json:"limit"`
	Offset   int    `json:"offset"`
}

type AccessUnresolvedIdentity struct {
	ID                    string `json:"id"`
	Protocol              string `json:"protocol"`
	IdentifierMasked      string `json:"identifierMasked"`
	Plate                 string `json:"plate"`
	Manufacturer          string `json:"manufacturer"`
	SourceEndpoint        string `json:"sourceEndpoint"`
	FirstRegisteredAt     string `json:"firstRegisteredAt"`
	LatestRegisteredAt    string `json:"latestRegisteredAt"`
	LatestAuthenticatedAt string `json:"latestAuthenticatedAt"`
	LatestSeenAt          string `json:"latestSeenAt"`
	FreshnessSec          int    `json:"freshnessSec"`
	IssueCode             string `json:"issueCode"`
	RecommendedAction     string `json:"recommendedAction"`
}

type AccessDistribution struct {
	Name       string  `json:"name"`
	Total      int     `json:"total"`
	Online     int     `json:"online"`
	OnlineRate float64 `json:"onlineRate"`
}

type AccessSummary struct {
	TotalVehicles       int                  `json:"totalVehicles"`
	OnlineVehicles      int                  `json:"onlineVehicles"`
	OfflineVehicles     int                  `json:"offlineVehicles"`
	LongOfflineVehicles int                  `json:"longOfflineVehicles"`
	NeverReported       int                  `json:"neverReported"`
	UnknownVehicles     int                  `json:"unknownVehicles"`
	DelayAbnormal       int                  `json:"delayAbnormal"`
	ReportedToday       int                  `json:"reportedToday"`
	HealthyVehicles     int                  `json:"healthyVehicles"`
	IncompleteVehicles  int                  `json:"incompleteVehicles"`
	DegradedVehicles    int                  `json:"degradedVehicles"`
	OnlineRate          float64              `json:"onlineRate"`
	Protocols           []AccessDistribution `json:"protocols"`
	OEMs                []AccessDistribution `json:"oems"`
	AsOf                string               `json:"asOf"`
	ThresholdVersion    int                  `json:"thresholdVersion"`
}

type AccessProtocolThreshold struct {
	Protocol     string `json:"protocol"`
	ThresholdSec int    `json:"thresholdSec"`
}

type AccessThresholdAudit struct {
	Version   int    `json:"version"`
	Actor     string `json:"actor"`
	ChangedAt string `json:"changedAt"`
	Summary   string `json:"summary"`
}

type AccessThresholdConfig struct {
	Version             int                       `json:"version"`
	DefaultThresholdSec int                       `json:"defaultThresholdSec"`
	DelayThresholdSec   int                       `json:"delayThresholdSec"`
	LongOfflineSec      int                       `json:"longOfflineSec"`
	Protocols           []AccessProtocolThreshold `json:"protocols"`
	UpdatedBy           string                    `json:"updatedBy"`
	UpdatedAt           string                    `json:"updatedAt"`
	Audit               []AccessThresholdAudit    `json:"audit"`
}

type AccessThresholdUpdate struct {
	Version             int                       `json:"version"`
	DefaultThresholdSec int                       `json:"defaultThresholdSec"`
	DelayThresholdSec   int                       `json:"delayThresholdSec"`
	LongOfflineSec      int                       `json:"longOfflineSec"`
	Protocols           []AccessProtocolThreshold `json:"protocols"`
	Actor               string                    `json:"actor"`
}

type AlertQuery struct {
	Keyword  string `json:"keyword"`
	Severity string `json:"severity"`
	Status   string `json:"status"`
	RuleID   string `json:"ruleId"`
	Protocol string `json:"protocol"`
	DateFrom string `json:"dateFrom"`
	DateTo   string `json:"dateTo"`
	Limit    int    `json:"limit"`
	Offset   int    `json:"offset"`
}

type AlertSummary struct {
	Active              int    `json:"active"`
	Unprocessed         int    `json:"unprocessed"`
	Processing          int    `json:"processing"`
	Recovered           int    `json:"recovered"`
	Closed              int    `json:"closed"`
	Ignored             int    `json:"ignored"`
	UnreadNotifications int    `json:"unreadNotifications"`
	AsOf                string `json:"asOf"`
}

type AlertRule struct {
	ID                   string   `json:"id"`
	Name                 string   `json:"name"`
	Description          string   `json:"description"`
	Severity             string   `json:"severity"`
	ValueType            string   `json:"valueType"`
	Metric               string   `json:"metric"`
	Operator             string   `json:"operator"`
	Threshold            float64  `json:"threshold"`
	ThresholdHigh        float64  `json:"thresholdHigh"`
	BooleanThreshold     *bool    `json:"booleanThreshold,omitempty"`
	DurationSec          int      `json:"durationSec"`
	RecoveryOperator     string   `json:"recoveryOperator"`
	RecoveryThreshold    float64  `json:"recoveryThreshold"`
	RepeatIntervalSec    int      `json:"repeatIntervalSec"`
	ScopeProtocols       []string `json:"scopeProtocols"`
	ScopeVINs            []string `json:"scopeVins"`
	ScopeOEMs            []string `json:"scopeOems"`
	ScopeModels          []string `json:"scopeModels"`
	ScopeCompanies       []string `json:"scopeCompanies"`
	NotificationChannels []string `json:"notificationChannels"`
	Enabled              bool     `json:"enabled"`
	Version              int      `json:"version"`
	CreatedBy            string   `json:"createdBy"`
	UpdatedBy            string   `json:"updatedBy"`
	CreatedAt            string   `json:"createdAt"`
	UpdatedAt            string   `json:"updatedAt"`
}

type AlertRuleInput struct {
	ID                   string   `json:"id"`
	Name                 string   `json:"name"`
	Description          string   `json:"description"`
	Severity             string   `json:"severity"`
	ValueType            string   `json:"valueType"`
	Metric               string   `json:"metric"`
	Operator             string   `json:"operator"`
	Threshold            float64  `json:"threshold"`
	ThresholdHigh        float64  `json:"thresholdHigh"`
	BooleanThreshold     *bool    `json:"booleanThreshold,omitempty"`
	DurationSec          int      `json:"durationSec"`
	RecoveryOperator     string   `json:"recoveryOperator"`
	RecoveryThreshold    float64  `json:"recoveryThreshold"`
	RepeatIntervalSec    int      `json:"repeatIntervalSec"`
	ScopeProtocols       []string `json:"scopeProtocols"`
	ScopeVINs            []string `json:"scopeVins"`
	ScopeOEMs            []string `json:"scopeOems"`
	ScopeModels          []string `json:"scopeModels"`
	ScopeCompanies       []string `json:"scopeCompanies"`
	NotificationChannels []string `json:"notificationChannels"`
	Enabled              bool     `json:"enabled"`
	Version              int      `json:"version"`
	Actor                string   `json:"actor"`
}

type AlertRuleEnabledUpdate struct {
	Version int    `json:"version"`
	Enabled bool   `json:"enabled"`
	Actor   string `json:"actor"`
}

type AlertEvent struct {
	ID            string        `json:"id"`
	RuleID        string        `json:"ruleId"`
	RuleName      string        `json:"ruleName"`
	RuleVersion   int           `json:"ruleVersion"`
	Severity      string        `json:"severity"`
	Status        string        `json:"status"`
	VIN           string        `json:"vin"`
	Plate         string        `json:"plate"`
	Protocol      string        `json:"protocol"`
	Metric        string        `json:"metric"`
	Operator      string        `json:"operator"`
	TriggerValue  float64       `json:"triggerValue"`
	Threshold     float64       `json:"threshold"`
	ThresholdHigh float64       `json:"thresholdHigh"`
	Unit          string        `json:"unit"`
	DurationSec   int           `json:"durationSec"`
	Location      string        `json:"location"`
	Longitude     *float64      `json:"longitude,omitempty"`
	Latitude      *float64      `json:"latitude,omitempty"`
	SourceEventID string        `json:"sourceEventId"`
	EventAt       string        `json:"eventAt"`
	ReceivedAt    string        `json:"receivedAt"`
	TriggeredAt   string        `json:"triggeredAt"`
	RecoveredAt   string        `json:"recoveredAt"`
	Handler       string        `json:"handler"`
	Version       int           `json:"version"`
	Actions       []AlertAction `json:"actions,omitempty"`
}

type AlertAction struct {
	ID         int64  `json:"id"`
	Action     string `json:"action"`
	FromStatus string `json:"fromStatus"`
	ToStatus   string `json:"toStatus"`
	Actor      string `json:"actor"`
	Note       string `json:"note"`
	CreatedAt  string `json:"createdAt"`
}

type AlertActionRequest struct {
	Version int    `json:"version"`
	Action  string `json:"action"`
	Actor   string `json:"actor"`
	Note    string `json:"note"`
}

type AlertNotification struct {
	ID        int64  `json:"id"`
	EventID   string `json:"eventId"`
	Title     string `json:"title"`
	Content   string `json:"content"`
	Severity  string `json:"severity"`
	Channel   string `json:"channel"`
	Read      bool   `json:"read"`
	CreatedAt string `json:"createdAt"`
	ReadAt    string `json:"readAt"`
}

type AlertNotificationQuery struct {
	UnreadOnly bool `json:"unreadOnly"`
	Limit      int  `json:"limit"`
	Offset     int  `json:"offset"`
}

type AlertNotificationReadRequest struct {
	IDs   []int64 `json:"ids"`
	Actor string  `json:"actor"`
}

type AlertEvaluationResult struct {
	RulesEvaluated        int    `json:"rulesEvaluated"`
	VehiclesScanned       int    `json:"vehiclesScanned"`
	CandidatesAdvanced    int    `json:"candidatesAdvanced"`
	DuplicateObservations int    `json:"duplicateObservations"`
	LateObservations      int    `json:"lateObservations"`
	StaleEvidenceSkipped  int    `json:"staleEvidenceSkipped"`
	Opened                int    `json:"opened"`
	Recovered             int    `json:"recovered"`
	AsOf                  string `json:"asOf"`
}

type DashboardSummary struct {
	OnlineVehicles  int                 `json:"onlineVehicles"`
	ActiveToday     int                 `json:"activeToday"`
	FrameToday      int                 `json:"frameToday"`
	IssueVehicles   int                 `json:"issueVehicles"`
	KafkaLag        *int                `json:"kafkaLag"`
	Protocols       []ProtocolStat      `json:"protocols"`
	ServiceStatuses []ServiceStatusStat `json:"serviceStatuses"`
	LinkHealth      []LinkHealth        `json:"linkHealth"`
}

type ProtocolStat struct {
	Protocol string `json:"protocol"`
	Online   int    `json:"online"`
	Total    int    `json:"total"`
}

type ServiceStatusStat struct {
	Status string `json:"status"`
	Title  string `json:"title"`
	Count  int    `json:"count"`
}

type LinkHealth struct {
	Name   string `json:"name"`
	Status string `json:"status"`
	Detail string `json:"detail,omitempty"`
}

type VehicleRow struct {
	VIN           string                `json:"vin"`
	Plate         string                `json:"plate"`
	Phone         string                `json:"phone"`
	OEM           string                `json:"oem"`
	Protocol      string                `json:"protocol"`
	Online        bool                  `json:"online"`
	LastSeen      string                `json:"lastSeen"`
	LocationText  string                `json:"locationText"`
	BindingScore  int                   `json:"bindingScore"`
	ServiceStatus *VehicleServiceStatus `json:"serviceStatus,omitempty"`
}

type VehicleCoverageRow struct {
	VIN               string                    `json:"vin"`
	Plate             string                    `json:"plate"`
	Phone             string                    `json:"phone"`
	OEM               string                    `json:"oem"`
	Protocols         []string                  `json:"protocols"`
	MissingProtocols  []string                  `json:"missingProtocols"`
	SourceStatus      []VehicleSourceStatus     `json:"sourceStatus"`
	SourceCount       int                       `json:"sourceCount"`
	OnlineSourceCount int                       `json:"onlineSourceCount"`
	Online            bool                      `json:"online"`
	LastSeen          string                    `json:"lastSeen"`
	BindingStatus     string                    `json:"bindingStatus"`
	ServiceStatus     *VehicleServiceStatus     `json:"serviceStatus,omitempty"`
	SourceConsistency *VehicleSourceConsistency `json:"sourceConsistency,omitempty"`
}

type VehicleCoverageSummary struct {
	TotalVehicles             int                       `json:"totalVehicles"`
	OnlineVehicles            int                       `json:"onlineVehicles"`
	SingleSourceVehicles      int                       `json:"singleSourceVehicles"`
	MultiSourceVehicles       int                       `json:"multiSourceVehicles"`
	NoDataVehicles            int                       `json:"noDataVehicles"`
	UnboundVehicles           int                       `json:"unboundVehicles"`
	ArchiveIncompleteVehicles int                       `json:"archiveIncompleteVehicles"`
	MissingSources            []MissingSourceStat       `json:"missingSources"`
	ArchiveMissingFields      []ArchiveMissingFieldStat `json:"archiveMissingFields"`
}

type VehicleIdentityResolution struct {
	LookupKey     string                `json:"lookupKey"`
	Resolved      bool                  `json:"resolved"`
	VIN           string                `json:"vin"`
	Plate         string                `json:"plate"`
	Phone         string                `json:"phone"`
	OEM           string                `json:"oem"`
	Protocols     []string              `json:"protocols"`
	Online        bool                  `json:"online"`
	LastSeen      string                `json:"lastSeen"`
	ServiceStatus *VehicleServiceStatus `json:"serviceStatus,omitempty"`
}

type VehicleDetail struct {
	VIN               string                     `json:"vin"`
	LookupKey         string                     `json:"lookupKey"`
	LookupResolved    bool                       `json:"lookupResolved"`
	Resolution        *VehicleIdentityResolution `json:"resolution,omitempty"`
	Identity          *VehicleRow                `json:"identity,omitempty"`
	Profile           *VehicleProfile            `json:"profile,omitempty"`
	RealtimeSummary   *VehicleRealtimeRow        `json:"realtimeSummary,omitempty"`
	ServiceStatus     *VehicleServiceStatus      `json:"serviceStatus,omitempty"`
	ServiceOverview   *VehicleServiceOverview    `json:"serviceOverview,omitempty"`
	SourceConsistency *VehicleSourceConsistency  `json:"sourceConsistency,omitempty"`
	Sources           []string                   `json:"sources"`
	SourceStatus      []VehicleSourceStatus      `json:"sourceStatus"`
	Realtime          []RealtimeLocationRow      `json:"realtime"`
	History           Page[HistoryLocationRow]   `json:"history"`
	Raw               Page[RawFrameRow]          `json:"raw"`
	Mileage           Page[DailyMileageRow]      `json:"mileage"`
	Quality           Page[QualityIssueRow]      `json:"quality"`
}

type VehicleProfile struct {
	VIN             string   `json:"vin"`
	ModelName       string   `json:"modelName"`
	VehicleType     string   `json:"vehicleType"`
	CompanyName     string   `json:"companyName"`
	OperationStatus string   `json:"operationStatus"`
	AccessProvider  string   `json:"accessProvider"`
	FirstAccessAt   string   `json:"firstAccessAt"`
	RuntimeSeconds  *int64   `json:"runtimeSeconds"`
	SourceSystem    string   `json:"sourceSystem"`
	SourceVersion   string   `json:"sourceVersion"`
	SyncedAt        string   `json:"syncedAt"`
	Version         int      `json:"version"`
	UpdatedBy       string   `json:"updatedBy"`
	UpdatedAt       string   `json:"updatedAt"`
	Completeness    int      `json:"completeness"`
	MissingFields   []string `json:"missingFields"`
}

type VehicleProfileInput struct {
	ModelName       string `json:"modelName"`
	VehicleType     string `json:"vehicleType"`
	CompanyName     string `json:"companyName"`
	OperationStatus string `json:"operationStatus"`
	AccessProvider  string `json:"accessProvider"`
	FirstAccessAt   string `json:"firstAccessAt"`
	RuntimeSeconds  *int64 `json:"runtimeSeconds"`
	Version         int    `json:"version"`
	Actor           string `json:"actor"`
}

type VehicleProfileSyncItem struct {
	VIN             string `json:"vin"`
	ModelName       string `json:"modelName"`
	VehicleType     string `json:"vehicleType"`
	CompanyName     string `json:"companyName"`
	OperationStatus string `json:"operationStatus"`
	AccessProvider  string `json:"accessProvider"`
	FirstAccessAt   string `json:"firstAccessAt"`
	RuntimeSeconds  *int64 `json:"runtimeSeconds"`
}

type VehicleProfileSyncRequest struct {
	SourceSystem   string                   `json:"sourceSystem"`
	SourceVersion  string                   `json:"sourceVersion"`
	ConflictPolicy string                   `json:"conflictPolicy"`
	DryRun         bool                     `json:"dryRun"`
	Items          []VehicleProfileSyncItem `json:"items"`
	Actor          string                   `json:"actor"`
}

type VehicleProfileSyncItemResult struct {
	VIN             string `json:"vin"`
	Status          string `json:"status"`
	PreviousSource  string `json:"previousSource,omitempty"`
	PreviousVersion string `json:"previousVersion,omitempty"`
	ProfileVersion  int    `json:"profileVersion,omitempty"`
}

type VehicleProfileSyncResult struct {
	SourceSystem  string                         `json:"sourceSystem"`
	SourceVersion string                         `json:"sourceVersion"`
	DryRun        bool                           `json:"dryRun"`
	Received      int                            `json:"received"`
	Created       int                            `json:"created"`
	Updated       int                            `json:"updated"`
	Unchanged     int                            `json:"unchanged"`
	Conflicted    int                            `json:"conflicted"`
	Missing       int                            `json:"missing"`
	Items         []VehicleProfileSyncItemResult `json:"items"`
}

type VehicleSourceConsistency struct {
	SourceCount            int      `json:"sourceCount"`
	OnlineSourceCount      int      `json:"onlineSourceCount"`
	LocatedSourceCount     int      `json:"locatedSourceCount"`
	MissingProtocols       []string `json:"missingProtocols"`
	MileageDeltaKm         float64  `json:"mileageDeltaKm"`
	SourceTimeDeltaSeconds float64  `json:"sourceTimeDeltaSeconds"`
	Scope                  string   `json:"scope"`
	Status                 string   `json:"status"`
	Severity               string   `json:"severity"`
	Title                  string   `json:"title"`
	Detail                 string   `json:"detail"`
}

type VehicleSourceEvidence struct {
	VIN                         string                          `json:"vin"`
	Plate                       string                          `json:"plate"`
	MileageDate                 string                          `json:"mileageDate"`
	RecommendedLocationProtocol string                          `json:"recommendedLocationProtocol"`
	RecommendedLocationLabel    string                          `json:"recommendedLocationLabel"`
	LocationConflict            bool                            `json:"locationConflict"`
	ConflictDistanceM           *float64                        `json:"conflictDistanceM,omitempty"`
	LocationSources             []VehicleLocationSourceEvidence `json:"locationSources"`
	MileageSources              []VehicleMileageSourceEvidence  `json:"mileageSources"`
	Comparison                  VehicleSourceEvidenceComparison `json:"comparison"`
	AsOf                        string                          `json:"asOf"`
}

type VehicleLocationSourceEvidence struct {
	Protocol               string   `json:"protocol"`
	SourceLabel            string   `json:"sourceLabel"`
	TerminalLabel          string   `json:"terminalLabel"`
	SourceKind             string   `json:"sourceKind"`
	SourceRef              string   `json:"sourceRef,omitempty"`
	SelectedWithinProtocol bool     `json:"selectedWithinProtocol"`
	Recommended            bool     `json:"recommended"`
	Enabled                bool     `json:"enabled"`
	Priority               int      `json:"priority"`
	Online                 bool     `json:"online"`
	QualityStatus          string   `json:"qualityStatus"`
	QualityReason          string   `json:"qualityReason"`
	Longitude              *float64 `json:"longitude,omitempty"`
	Latitude               *float64 `json:"latitude,omitempty"`
	SpeedKmh               *float64 `json:"speedKmh,omitempty"`
	TotalMileageKm         *float64 `json:"totalMileageKm,omitempty"`
	SOCPercent             *float64 `json:"socPercent,omitempty"`
	EventTime              string   `json:"eventTime"`
	ReceivedAt             string   `json:"receivedAt"`
	FirstSeenAt            string   `json:"firstSeenAt,omitempty"`
	ReportIntervalSec      *int     `json:"reportIntervalSec,omitempty"`
	ReportSampleCount      int64    `json:"reportSampleCount,omitempty"`
	SelectionReason        string   `json:"selectionReason,omitempty"`
	sourceKey              string
}

type VehicleMileageSourceEvidence struct {
	Protocol               string   `json:"protocol"`
	SourceLabel            string   `json:"sourceLabel"`
	TerminalLabel          string   `json:"terminalLabel"`
	SourceKind             string   `json:"sourceKind"`
	SelectedWithinProtocol bool     `json:"selectedWithinProtocol"`
	Recommended            bool     `json:"recommended"`
	Enabled                bool     `json:"enabled"`
	Priority               int      `json:"priority"`
	QualityStatus          string   `json:"qualityStatus"`
	QualityReason          string   `json:"qualityReason"`
	FirstTotalMileageKm    *float64 `json:"firstTotalMileageKm,omitempty"`
	LatestTotalMileageKm   *float64 `json:"latestTotalMileageKm,omitempty"`
	DailyMileageKm         *float64 `json:"dailyMileageKm,omitempty"`
	SampleCount            int64    `json:"sampleCount"`
	FirstEventTime         string   `json:"firstEventTime"`
	LatestEventTime        string   `json:"latestEventTime"`
	sourceKey              string
}

type VehicleSourceEvidenceComparison struct {
	LocationMaxDistanceM   float64 `json:"locationMaxDistanceM"`
	TotalMileageDeltaKm    float64 `json:"totalMileageDeltaKm"`
	DailyMileageDeltaKm    float64 `json:"dailyMileageDeltaKm"`
	ReportTimeDeltaSeconds float64 `json:"reportTimeDeltaSeconds"`
}

type VehicleSourceDiagnostic struct {
	Evidence             VehicleSourceEvidence     `json:"evidence"`
	Access               *AccessVehicleRow         `json:"access,omitempty"`
	Policy               VehicleSourcePolicyConfig `json:"policy"`
	RecommendationReason string                    `json:"recommendationReason"`
	RefreshHint          string                    `json:"refreshHint"`
}

type VehicleSourcePolicyConfig struct {
	VIN       string                     `json:"vin"`
	Version   int                        `json:"version"`
	UpdatedBy string                     `json:"updatedBy"`
	UpdatedAt string                     `json:"updatedAt"`
	Audit     []VehicleSourcePolicyAudit `json:"audit"`
}

type VehicleSourcePolicyAudit struct {
	Version     int    `json:"version"`
	Protocol    string `json:"protocol"`
	SourceRef   string `json:"sourceRef"`
	SourceLabel string `json:"sourceLabel"`
	Actor       string `json:"actor"`
	ChangedAt   string `json:"changedAt"`
	Summary     string `json:"summary"`
}

type VehicleSourcePolicyUpdate struct {
	Version   int    `json:"version"`
	SourceRef string `json:"sourceRef"`
	Enabled   bool   `json:"enabled"`
	Priority  int    `json:"priority"`
	Remark    string `json:"remark"`
	Actor     string `json:"actor"`
}

type vehicleSourcePolicyStoreUpdate struct {
	VehicleSourcePolicyUpdate
	VIN             string
	Protocol        string
	SourceKey       string
	SourceLabel     string
	CurrentEnabled  bool
	CurrentPriority int
	CurrentRemark   string
}

type vehicleLocationSourceHistory struct {
	Protocol          string
	sourceKey         string
	FirstSeenAt       string
	LastSeenAt        string
	ReportSampleCount int64
}

type VehicleServiceOverview struct {
	VIN               string                    `json:"vin"`
	Plate             string                    `json:"plate"`
	Phone             string                    `json:"phone"`
	OEM               string                    `json:"oem"`
	Protocols         []string                  `json:"protocols"`
	PrimaryProtocol   string                    `json:"primaryProtocol"`
	CoverageStatus    string                    `json:"coverageStatus"`
	SourceCount       int                       `json:"sourceCount"`
	OnlineSourceCount int                       `json:"onlineSourceCount"`
	LastSeen          string                    `json:"lastSeen"`
	RealtimeCount     int                       `json:"realtimeCount"`
	HistoryCount      int                       `json:"historyCount"`
	RawCount          int                       `json:"rawCount"`
	MileageCount      int                       `json:"mileageCount"`
	QualityIssueCount int                       `json:"qualityIssueCount"`
	ServiceStatus     *VehicleServiceStatus     `json:"serviceStatus,omitempty"`
	SourceConsistency *VehicleSourceConsistency `json:"sourceConsistency,omitempty"`
}

type VehicleServiceSummary struct {
	TotalVehicles             int                       `json:"totalVehicles"`
	BoundVehicles             int                       `json:"boundVehicles"`
	OnlineVehicles            int                       `json:"onlineVehicles"`
	SingleSourceVehicles      int                       `json:"singleSourceVehicles"`
	MultiSourceVehicles       int                       `json:"multiSourceVehicles"`
	NoDataVehicles            int                       `json:"noDataVehicles"`
	IdentityRequiredVehicles  int                       `json:"identityRequiredVehicles"`
	ArchiveIncompleteVehicles int                       `json:"archiveIncompleteVehicles"`
	ServiceStatuses           []ServiceStatusStat       `json:"serviceStatuses"`
	Protocols                 []ProtocolStat            `json:"protocols"`
	MissingSources            []MissingSourceStat       `json:"missingSources"`
	ArchiveMissingFields      []ArchiveMissingFieldStat `json:"archiveMissingFields"`
}

type VehicleServiceStatus struct {
	Status            string `json:"status"`
	Severity          string `json:"severity"`
	Title             string `json:"title"`
	Detail            string `json:"detail"`
	SourceCount       int    `json:"sourceCount"`
	OnlineSourceCount int    `json:"onlineSourceCount"`
}

type MissingSourceStat struct {
	Protocol string `json:"protocol"`
	Count    int    `json:"count"`
}

type SourceReadinessPlan struct {
	TotalVehicles            int                  `json:"totalVehicles"`
	BoundVehicles            int                  `json:"boundVehicles"`
	IdentityRequiredVehicles int                  `json:"identityRequiredVehicles"`
	OnlineVehicles           int                  `json:"onlineVehicles"`
	KafkaLag                 *int                 `json:"kafkaLag"`
	ActiveConnections        *int                 `json:"activeConnections"`
	RedisOnlineKeys          *int                 `json:"redisOnlineKeys"`
	PlatformRelease          string               `json:"platformRelease"`
	Sources                  []SourceReadinessRow `json:"sources"`
}

type SourceReadinessRow struct {
	Protocol        string  `json:"protocol"`
	Role            string  `json:"role"`
	Online          int     `json:"online"`
	Total           int     `json:"total"`
	OnlineRate      float64 `json:"onlineRate"`
	MissingVehicles int     `json:"missingVehicles"`
	Severity        string  `json:"severity"`
	Status          string  `json:"status"`
	Evidence        string  `json:"evidence"`
	Action          string  `json:"action"`
	Acceptance      string  `json:"acceptance"`
	VehiclesHash    string  `json:"vehiclesHash"`
	RealtimeHash    string  `json:"realtimeHash"`
	HistoryHash     string  `json:"historyHash"`
	AlertHash       string  `json:"alertHash"`
}

type ArchiveMissingFieldStat struct {
	Field string `json:"field"`
	Title string `json:"title"`
	Count int    `json:"count"`
}

type VehicleSourceStatus struct {
	Protocol    string `json:"protocol"`
	Online      bool   `json:"online"`
	LastSeen    string `json:"lastSeen"`
	HasRealtime bool   `json:"hasRealtime"`
	HasHistory  bool   `json:"hasHistory"`
	HasRaw      bool   `json:"hasRaw"`
	HasMileage  bool   `json:"hasMileage"`
}

type RealtimeLocationRow struct {
	VIN            string  `json:"vin"`
	Plate          string  `json:"plate"`
	Protocol       string  `json:"protocol"`
	Longitude      float64 `json:"longitude"`
	Latitude       float64 `json:"latitude"`
	SpeedKmh       float64 `json:"speedKmh"`
	SOCPercent     float64 `json:"socPercent"`
	TotalMileageKm float64 `json:"totalMileageKm"`
	LastSeen       string  `json:"lastSeen"`
}

type VehicleRealtimeRow struct {
	VIN                   string                `json:"vin"`
	Plate                 string                `json:"plate"`
	Phone                 string                `json:"phone"`
	OEM                   string                `json:"oem"`
	Protocols             []string              `json:"protocols"`
	SourceStatus          []VehicleSourceStatus `json:"sourceStatus"`
	SourceCount           int                   `json:"sourceCount"`
	OnlineSourceCount     int                   `json:"onlineSourceCount"`
	Online                bool                  `json:"online"`
	BindingStatus         string                `json:"bindingStatus"`
	ServiceStatus         *VehicleServiceStatus `json:"serviceStatus,omitempty"`
	PrimaryProtocol       string                `json:"primaryProtocol"`
	LocationSource        string                `json:"locationSource"`
	LocationConflict      bool                  `json:"locationConflict"`
	ConflictDistanceM     *float64              `json:"conflictDistanceM,omitempty"`
	LocationAvailable     bool                  `json:"locationAvailable"`
	Longitude             float64               `json:"longitude"`
	Latitude              float64               `json:"latitude"`
	SpeedAvailable        bool                  `json:"speedAvailable"`
	SpeedKmh              float64               `json:"speedKmh"`
	SOCAvailable          bool                  `json:"socAvailable"`
	SOCPercent            float64               `json:"socPercent"`
	MileageAvailable      bool                  `json:"mileageAvailable"`
	TotalMileageKm        float64               `json:"totalMileageKm"`
	TodayMileageAvailable bool                  `json:"todayMileageAvailable"`
	TodayMileageKm        float64               `json:"todayMileageKm"`
	LastSeen              string                `json:"lastSeen"`
	ReportIntervalMs      *int64                `json:"reportIntervalMs,omitempty"`
}

type HistoryLocationRow struct {
	VIN            string  `json:"vin"`
	Plate          string  `json:"plate"`
	Protocol       string  `json:"protocol"`
	Longitude      float64 `json:"longitude"`
	Latitude       float64 `json:"latitude"`
	SpeedKmh       float64 `json:"speedKmh"`
	SOCPercent     float64 `json:"socPercent"`
	SOCAvailable   bool    `json:"socAvailable"`
	DirectionDeg   *int64  `json:"directionDeg,omitempty"`
	AlarmFlag      *int64  `json:"alarmFlag,omitempty"`
	TotalMileageKm float64 `json:"totalMileageKm"`
	DeviceTime     string  `json:"deviceTime"`
	ServerTime     string  `json:"serverTime"`
}

type RawFrameRow struct {
	ID             string         `json:"id"`
	VIN            string         `json:"vin"`
	Plate          string         `json:"plate"`
	Protocol       string         `json:"protocol"`
	FrameType      string         `json:"frameType"`
	DeviceTime     string         `json:"deviceTime"`
	ServerTime     string         `json:"serverTime"`
	RawSizeBytes   int            `json:"rawSizeBytes"`
	ParseStatus    string         `json:"parseStatus,omitempty"`
	ParseError     string         `json:"parseError,omitempty"`
	SourceEndpoint string         `json:"sourceEndpoint,omitempty"`
	ParsedFields   map[string]any `json:"parsedFields"`
}

type LatestTelemetryCategory struct {
	Key   string `json:"key"`
	Label string `json:"label"`
	Count int    `json:"count"`
}

type LatestTelemetryValue struct {
	Key              string `json:"key"`
	SourceField      string `json:"sourceField"`
	Label            string `json:"label"`
	Description      string `json:"description,omitempty"`
	Unit             string `json:"unit"`
	Category         string `json:"category"`
	ValueType        string `json:"valueType"`
	Value            any    `json:"value"`
	Protocol         string `json:"protocol"`
	SourceEndpoint   string `json:"sourceEndpoint,omitempty"`
	FrameID          string `json:"frameId"`
	DeviceTime       string `json:"deviceTime"`
	ServerTime       string `json:"serverTime"`
	Quality          string `json:"quality"`
	QualityReason    string `json:"qualityReason"`
	FreshnessSeconds int64  `json:"freshnessSeconds"`
	DataDelaySeconds *int64 `json:"dataDelaySeconds,omitempty"`
}

type LatestTelemetryResponse struct {
	VIN               string                    `json:"vin"`
	Categories        []LatestTelemetryCategory `json:"categories"`
	Values            []LatestTelemetryValue    `json:"values"`
	AsOf              string                    `json:"asOf"`
	StaleAfterSeconds int64                     `json:"staleAfterSeconds"`
	ScannedFrames     int                       `json:"scannedFrames"`
	Evidence          string                    `json:"evidence"`
}

type DailyMileageRow struct {
	VIN             string  `json:"vin"`
	Plate           string  `json:"plate"`
	Date            string  `json:"date"`
	StartMileageKm  float64 `json:"startMileageKm"`
	EndMileageKm    float64 `json:"endMileageKm"`
	DailyMileageKm  float64 `json:"dailyMileageKm"`
	Source          string  `json:"source"`
	AnomalySeverity string  `json:"anomalySeverity,omitempty"`
}

type MileageSummary struct {
	VehicleCount         int     `json:"vehicleCount"`
	RecordCount          int     `json:"recordCount"`
	SourceCount          int     `json:"sourceCount"`
	TotalMileageKm       float64 `json:"totalMileageKm"`
	AverageMileagePerVIN float64 `json:"averageMileagePerVin"`
}

type MileageTrendPoint struct {
	Date      string  `json:"date"`
	MileageKm float64 `json:"mileageKm"`
	Vehicles  int     `json:"vehicles"`
}

type MileageVehicleRank struct {
	VIN             string  `json:"vin"`
	Plate           string  `json:"plate"`
	MileageKm       float64 `json:"mileageKm"`
	LatestMileageKm float64 `json:"latestMileageKm"`
	ActiveDays      int     `json:"activeDays"`
}

type MileageStatistics struct {
	DateFrom              string               `json:"dateFrom"`
	DateTo                string               `json:"dateTo"`
	VehicleCount          int                  `json:"vehicleCount"`
	RecordCount           int                  `json:"recordCount"`
	SourceCount           int                  `json:"sourceCount"`
	PeriodMileageKm       float64              `json:"periodMileageKm"`
	FleetLatestMileageKm  float64              `json:"fleetLatestMileageKm"`
	AverageMileagePerVIN  float64              `json:"averageMileagePerVin"`
	AverageDailyMileageKm float64              `json:"averageDailyMileageKm"`
	Trend                 []MileageTrendPoint  `json:"trend"`
	Ranking               []MileageVehicleRank `json:"ranking"`
	AsOf                  string               `json:"asOf"`
	Evidence              string               `json:"evidence"`
}

type OnlineStatisticsSummary struct {
	VehicleCount        int            `json:"vehicleCount"`
	OnlineVehicleCount  int            `json:"onlineVehicleCount"`
	OfflineVehicleCount int            `json:"offlineVehicleCount"`
	OnlineRatePercent   float64        `json:"onlineRatePercent"`
	RedisOnlineKeys     *int           `json:"redisOnlineKeys"`
	ProtocolStats       []ProtocolStat `json:"protocolStats"`
	Evidence            string         `json:"evidence"`
}

type OnlineVehicleStatusRow struct {
	VIN                    string   `json:"vin"`
	Plate                  string   `json:"plate"`
	Phone                  string   `json:"phone"`
	OEM                    string   `json:"oem"`
	Protocols              []string `json:"protocols"`
	Online                 bool     `json:"online"`
	LastSeen               string   `json:"lastSeen"`
	OfflineDurationMinutes *int     `json:"offlineDurationMinutes"`
	SourceCount            int      `json:"sourceCount"`
	OnlineSourceCount      int      `json:"onlineSourceCount"`
	BindingStatus          string   `json:"bindingStatus"`
}

type QualityIssueRow struct {
	VIN            string `json:"vin"`
	Plate          string `json:"plate"`
	Phone          string `json:"phone"`
	SourceEndpoint string `json:"sourceEndpoint"`
	Protocol       string `json:"protocol"`
	IssueType      string `json:"issueType"`
	Severity       string `json:"severity"`
	LastSeen       string `json:"lastSeen"`
	Detail         string `json:"detail"`
}

type QualitySummary struct {
	IssueVehicleCount int                 `json:"issueVehicleCount"`
	IssueRecordCount  int                 `json:"issueRecordCount"`
	ErrorCount        int                 `json:"errorCount"`
	WarningCount      int                 `json:"warningCount"`
	Protocols         []QualityBucketStat `json:"protocols"`
	IssueTypes        []QualityBucketStat `json:"issueTypes"`
}

type QualityBucketStat struct {
	Name  string `json:"name"`
	Count int    `json:"count"`
}

type QualityNotificationPlan struct {
	Summary         QualitySummary              `json:"summary"`
	Rules           []QualityAlertRule          `json:"rules"`
	Policies        []QualityNotificationPolicy `json:"policies"`
	PriorityIssues  []QualityPriorityIssue      `json:"priorityIssues"`
	ActiveRuleCount int                         `json:"activeRuleCount"`
	P0RuleCount     int                         `json:"p0RuleCount"`
}

type QualityAlertRule struct {
	IssueType string `json:"issueType"`
	Title     string `json:"title"`
	Level     string `json:"level"`
	Owner     string `json:"owner"`
	Trigger   string `json:"trigger"`
	Notify    string `json:"notify"`
	SLA       string `json:"sla"`
	Count     int    `json:"count"`
}

type QualityNotificationPolicy struct {
	Name               string `json:"name"`
	Target             string `json:"target"`
	Channel            string `json:"channel"`
	Condition          string `json:"condition"`
	EscalationMinutes  int    `json:"escalationMinutes"`
	AcceptanceCriteria string `json:"acceptanceCriteria"`
}

type QualityPriorityIssue struct {
	QualityIssueRow
	Priority         string `json:"priority"`
	ActionLabel      string `json:"actionLabel"`
	ActionDetail     string `json:"actionDetail"`
	SLA              string `json:"sla"`
	VehicleLabel     string `json:"vehicleLabel"`
	RealtimeHash     string `json:"realtimeHash"`
	HistoryHash      string `json:"historyHash"`
	RawHash          string `json:"rawHash"`
	VehicleHash      string `json:"vehicleHash"`
	NotificationText string `json:"notificationText"`
}

type OpsHealth struct {
	LinkHealth        []LinkHealth      `json:"linkHealth"`
	KafkaLag          *int              `json:"kafkaLag"`
	ActiveConnections *int              `json:"activeConnections"`
	CapacityMetrics   CapacityMetrics   `json:"capacityMetrics"`
	CapacityFindings  []string          `json:"capacityFindings"`
	RedisOnlineKeys   *int              `json:"redisOnlineKeys"`
	TDengineWritable  bool              `json:"tdengineWritable"`
	MySQLWritable     bool              `json:"mysqlWritable"`
	AlertStream       AlertStreamHealth `json:"alertStream"`
	Runtime           RuntimeInfo       `json:"runtime"`
}

type AlertStreamHealth struct {
	Mode            string `json:"mode"`
	ConsumerGroup   string `json:"consumerGroup"`
	Partitions      int    `json:"partitions"`
	Lag             int64  `json:"lag"`
	Processed       int64  `json:"processed"`
	Valid           int64  `json:"valid"`
	Invalid         int64  `json:"invalid"`
	Late            int64  `json:"late"`
	ReplaySkipped   int64  `json:"replaySkipped"`
	UpdatedAt       string `json:"updatedAt"`
	LastInvalidCode string `json:"lastInvalidCode"`
	LastInvalidAt   string `json:"lastInvalidAt"`
}

type CapacityMetrics struct {
	ActiveConnections          int `json:"activeConnections"`
	KafkaLag                   int `json:"kafkaLag"`
	BridgeConsumerPending      int `json:"bridgeConsumerPending"`
	BridgeAckPending           int `json:"bridgeAckPending"`
	BridgeBatchPendingMessages int `json:"bridgeBatchPendingMessages"`
	FastWriterConsumerPending  int `json:"fastWriterConsumerPending"`
	FastWriterAckPending       int `json:"fastWriterAckPending"`
	FastWriterBatchPending     int `json:"fastWriterBatchPending"`
	HistoryBatchPending        int `json:"historyBatchPending"`
	HistoryRowsPending         int `json:"historyRowsPending"`
}

type RuntimeInfo struct {
	DataMode                 string `json:"dataMode"`
	ExportDir                string `json:"-"`
	RequestTimeoutMs         int    `json:"requestTimeoutMs"`
	AMapWebJSConfigured      bool   `json:"amapWebJsConfigured"`
	AMapAPIConfigured        bool   `json:"amapApiConfigured"`
	AMapSecurityProxyEnabled bool   `json:"amapSecurityProxyEnabled"`
	AMapSecurityCodeExposed  bool   `json:"amapSecurityCodeExposed"`
	AMapSecurityServiceHost  string `json:"amapSecurityServiceHost"`
	PlatformRelease          string `json:"platformRelease"`
	AlertStreamMode          string `json:"alertStreamMode"`
	AlertStreamConsumerGroup string `json:"alertStreamConsumerGroup"`
}
