package services

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

type programService struct {
	repository repositories.ProgramRepository
}

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

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

func NewProgramService(repository repositories.ProgramRepository) ProgramService {
	return &programService{
		repository: repository,
	}
}

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

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

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

func (s *programService) Create(program *models.Program) (*models.Program, error) {
	result, err := s.repository.Create(program)

	return result, err
}

func (s *programService) Update(program *models.Program) (*models.Program, error) {
	result, err := s.repository.Update(program)

	return result, err
}

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

	return err
}
