package service

import (
	"context"

	"wucher/internal/domain/operation"
)

type HEMSOperationCategoryService struct {
	repo operation.HEMSOperationCategoryRepository
}

func NewHEMSOperationCategoryService(repo operation.HEMSOperationCategoryRepository) *HEMSOperationCategoryService {
	return &HEMSOperationCategoryService{repo: repo}
}

func (s *HEMSOperationCategoryService) Create(ctx context.Context, category *operation.HEMSOperationCategory) error {
	return s.repo.Create(ctx, category)
}

func (s *HEMSOperationCategoryService) Update(ctx context.Context, category *operation.HEMSOperationCategory) error {
	return s.repo.Update(ctx, category)
}

func (s *HEMSOperationCategoryService) Delete(ctx context.Context, id []byte, deletedBy []byte) error {
	return s.repo.Delete(ctx, id, deletedBy)
}

func (s *HEMSOperationCategoryService) GetByID(ctx context.Context, id []byte) (*operation.HEMSOperationCategory, error) {
	return s.repo.GetByID(ctx, id)
}

func (s *HEMSOperationCategoryService) List(ctx context.Context, filter string, sort string, limit, offset int) ([]operation.HEMSOperationCategory, int64, error) {
	return s.repo.List(ctx, filter, normalizeHEMSOperationCategorySort(sort), limit, offset)
}

func normalizeHEMSOperationCategorySort(sort string) string {
	return normalizeSortByRules(sort,
		sortField("name"),
		sortField("type"),
		sortField("created_at"),
		sortField("updated_at"),
	)
}
