package service

import (
	"io"
	"time"

	"github.com/seifghazi/claude-code-monitor/internal/config"
	"github.com/seifghazi/claude-code-monitor/internal/model"
)

type StorageService interface {
	// Core CRUD operations
	SaveRequest(request *model.RequestLog) (string, error)
	GetRequests(page, limit int, modelFilter string) ([]model.RequestLog, int, error)
	GetAllRequests(modelFilter string) ([]*model.RequestLog, error)
	GetRequestByShortID(shortID string) (*model.RequestLog, string, error)
	ClearRequests() (int, error)

	// Update operations
	UpdateRequestWithGrading(requestID string, grade *model.PromptGrade) error
	UpdateRequestWithResponse(request *model.RequestLog) error

	// Maintenance operations
	DeleteRequestsOlderThan(age time.Duration) (int, error)
	GetDatabaseStats() (map[string]interface{}, error)

	// Usage statistics
	GetUsageStats(startDate, endDate, modelFilter, orgFilter string) (*model.UsageStats, error)

	// Dashboard statistics (fast aggregated queries)
	GetRequestsSummary(modelFilter string) ([]*model.RequestSummary, error)
	GetRequestsSummaryPaginated(modelFilter, startTime, endTime string, offset, limit int) ([]*model.RequestSummary, int, error)
	GetStats(startDate, endDate, orgFilter string) (*model.DashboardStats, error)
	GetHourlyStats(startTime, endTime string, bucketMinutes int, orgFilter string) (*model.HourlyStatsResponse, error)
	GetModelStats(startTime, endTime, orgFilter string) (*model.ModelStatsResponse, error)
	GetLatestRequestDate() (*time.Time, error)
	GetDistinctOrganizations() ([]string, error)

	// Settings (dynamic proxy config)
	GetSettings() (*model.ProxySettings, error)
	SaveSettings(settings *model.ProxySettings) error

	// Configuration
	GetConfig() *config.StorageConfig
	EnsureDirectoryExists() error

	// Cleanup - implements io.Closer
	io.Closer
}
