package category

import (
	"context"
	"tercul/internal/domain"
)

// CategoryQueries contains the query handlers for the category aggregate.
type CategoryQueries struct {
	repo domain.CategoryRepository
}

// NewCategoryQueries creates a new CategoryQueries handler.
func NewCategoryQueries(repo domain.CategoryRepository) *CategoryQueries {
	return &CategoryQueries{repo: repo}
}

// Category returns a category by ID.
func (q *CategoryQueries) Category(ctx context.Context, id uint) (*domain.Category, error) {
	return q.repo.GetByID(ctx, id)
}

// CategoryByName returns a category by name.
func (q *CategoryQueries) CategoryByName(ctx context.Context, name string) (*domain.Category, error) {
	return q.repo.FindByName(ctx, name)
}

// CategoriesByWorkID returns all categories for a work.
func (q *CategoryQueries) CategoriesByWorkID(ctx context.Context, workID uint) ([]domain.Category, error) {
	return q.repo.ListByWorkID(ctx, workID)
}

// CategoriesByParentID returns all categories for a parent.
func (q *CategoryQueries) CategoriesByParentID(ctx context.Context, parentID *uint) ([]domain.Category, error) {
	return q.repo.ListByParentID(ctx, parentID)
}

// Categories returns all categories.
func (q *CategoryQueries) Categories(ctx context.Context) ([]domain.Category, error) {
	return q.repo.ListAll(ctx)
}
