package services

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

type examService struct {
	repository repositories.ExamRepository
}

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

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

func NewExamService(repository repositories.ExamRepository) ExamService {
	return &examService{
		repository: repository,
	}
}

func (s *examService) List(q string, page int, limit int) (*[]models.Exam, error) {
	return s.repository.List(q, page, limit)
}

func (s *examService) Total(q string) (int64, error) {
	return s.repository.Total(q)
}

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

func (s *examService) Create(exam *models.Exam) (*models.Exam, error) {
	result, err := s.repository.Create(exam)

	return result, err
}

func (s *examService) Update(exam *models.Exam) (*models.Exam, error) {
	result, err := s.repository.Update(exam)

	return result, err
}

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

	return err
}
