package adminfinance

import (
	"context"
	"errors"
)

var ErrDependencyUnavailable = errors.New("dependency unavailable")

type Service struct {
	repo *Repository
}

func NewService(repo *Repository) *Service {
	return &Service{repo: repo}
}

func (s *Service) Dashboard(ctx context.Context, query DashboardQuery) (*DashboardDTO, error) {
	if s.repo == nil {
		return nil, ErrDependencyUnavailable
	}
	return s.repo.Dashboard(ctx, query)
}

func (s *Service) Details(ctx context.Context, query DetailQuery) (*PaginatedResult, error) {
	if s.repo == nil {
		return nil, ErrDependencyUnavailable
	}
	if query.Page < 1 {
		query.Page = 1
	}
	if query.PageSize < 1 {
		query.PageSize = 20
	}
	if query.PageSize > 100 {
		query.PageSize = 100
	}
	return s.repo.Details(ctx, query)
}
