package service

import (
	"context"

	"cmr-backend/internal/store/postgres"
)

type OpsOverviewSummary struct {
	ManagedAssets   int `json:"managedAssets"`
	Places          int `json:"places"`
	MapAssets       int `json:"mapAssets"`
	TileReleases    int `json:"tileReleases"`
	CourseSets      int `json:"courseSets"`
	CourseVariants  int `json:"courseVariants"`
	Events          int `json:"events"`
	DefaultEvents   int `json:"defaultEvents"`
	PublishedEvents int `json:"publishedEvents"`
	ConfigSources   int `json:"configSources"`
	Releases        int `json:"releases"`
	RuntimeBindings int `json:"runtimeBindings"`
	Presentations   int `json:"presentations"`
	ContentBundles  int `json:"contentBundles"`
	OpsUsers        int `json:"opsUsers"`
}

type OpsSummaryService struct {
	store *postgres.Store
}

func NewOpsSummaryService(store *postgres.Store) *OpsSummaryService {
	return &OpsSummaryService{store: store}
}

func (s *OpsSummaryService) GetOverview(ctx context.Context) (*OpsOverviewSummary, error) {
	counts, err := s.store.GetOpsOverviewCounts(ctx)
	if err != nil {
		return nil, err
	}
	return &OpsOverviewSummary{
		ManagedAssets:   counts.ManagedAssets,
		Places:          counts.Places,
		MapAssets:       counts.MapAssets,
		TileReleases:    counts.TileReleases,
		CourseSets:      counts.CourseSets,
		CourseVariants:  counts.CourseVariants,
		Events:          counts.Events,
		DefaultEvents:   counts.DefaultEvents,
		PublishedEvents: counts.PublishedEvents,
		ConfigSources:   counts.ConfigSources,
		Releases:        counts.Releases,
		RuntimeBindings: counts.RuntimeBindings,
		Presentations:   counts.Presentations,
		ContentBundles:  counts.ContentBundles,
		OpsUsers:        counts.OpsUsers,
	}, nil
}
