package services

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

type userService struct {
	repository      repositories.UserRepository
	tokenRepository repositories.TokenRepository
}

type UserService interface {
	List(string, int, int) (*[]models.User, error)
	Total(string) (int64, error)
	Find(string) (*models.User, error)
	FindByUsername(string) (*models.User, error)
	Create(*models.User) (*models.User, error)
}

func NewUserService(repository repositories.UserRepository, tokenRepository repositories.TokenRepository) UserService {
	return &userService{
		repository:      repository,
		tokenRepository: tokenRepository,
	}
}

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

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

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

func (s *userService) FindByUsername(username string) (*models.User, error) {
	return s.repository.FindByUsername(username)
}

func (s *userService) Create(user *models.User) (*models.User, error) {
	result, err := s.repository.Create(user)

	return result, err
}
