// Code generated by candi v1.3.1.

package usecase

import (
	"context"

	"monorepo/services/line-chatbot/internal/modules/event/domain"
	"monorepo/services/line-chatbot/pkg/shared/repository"

	"pkg.agungdp.dev/candi/candishared"
	"pkg.agungdp.dev/candi/codebase/factory/dependency"
	"pkg.agungdp.dev/candi/codebase/interfaces"
)

type eventUsecaseImpl struct {
	cache interfaces.Cache

	repoMongo *repository.RepoMongo
}

// NewEventUsecase usecase impl constructor
func NewEventUsecase(deps dependency.Dependency) EventUsecase {
	return &eventUsecaseImpl{
		cache: deps.GetRedisPool().Cache(),

		repoMongo: repository.GetSharedRepoMongo(),
	}
}

func (uc *eventUsecaseImpl) FindAll(ctx context.Context, filter *candishared.Filter) (events []domain.Event, meta candishared.Meta, err error) {
	filter.CalculateOffset()

	count := uc.repoMongo.EventRepo.Count(ctx, filter)
	repoRes := <-uc.repoMongo.EventRepo.FindAll(ctx, filter)
	if repoRes.Error != nil {
		err = repoRes.Error
		return
	}

	events = repoRes.Data.([]domain.Event)
	meta = candishared.NewMeta(int(filter.Page), int(filter.Limit), <-count)

	return
}
