package services

import (
	"learnsteam/learsteam-quiz-api/internal/models"
	"learnsteam/learsteam-quiz-api/internal/repositories"
)

type quizService struct {
	repository repositories.QuizRepository
}

type QuizService interface {
	List(string, int, int) (*[]models.Quiz, error)
	Total(string) (int64, error)

	Find(string) (*models.Quiz, error)
	Create(*models.Quiz) (*models.Quiz, error)
	Update(*models.Quiz) (*models.Quiz, error)
	Delete(string) error
}

func NewQuizService(repository repositories.QuizRepository) QuizService {
	return &quizService{
		repository: repository,
	}
}

func (s *quizService) List(program_id string, page int, limit int) (*[]models.Quiz, error) {
	return s.repository.List(program_id, page, limit)
}

func (s *quizService) Total(tag string) (int64, error) {
	return s.repository.Total(tag)
}

func (s *quizService) Find(id string) (*models.Quiz, error) {
	return s.repository.Find(id)
}

func (s *quizService) Create(quiz *models.Quiz) (*models.Quiz, error) {
	result, err := s.repository.Create(quiz)

	return result, err
}

func (s *quizService) Update(quiz *models.Quiz) (*models.Quiz, error) {
	result, err := s.repository.Update(quiz)

	return result, err
}

func (s *quizService) Delete(id string) error {
	err := s.repository.Delete(id)

	return err
}
