package service

import (
	"fmt"
)

type StaffService struct {
	repo StaffRepository
}

func NewStaffService(repo StaffRepository) *StaffService {
	return &StaffService{
		repo: repo,
	}
}

func (s *StaffService) RegisterStaff(name, lastname, phone string) (Staff, error) {
	newStaff := Staff{
		Name:        name,
		LastName:    lastname,
		PhoneNumber: phone,
	}
	createdStaff, err := s.repo.Create(newStaff)
	if err != nil {
		return Staff{}, fmt.Errorf("Error in registring staff%w", err)
	}
	return createdStaff, nil
}

func (s *StaffService) Get(id int) (*Staff, error) {
	return s.repo.Get(id)
}

func (s *StaffService) List() ([]Staff, error) {
	return s.repo.List()
}

func (s *StaffService) Remove(id int) error {
	return s.repo.Remove(id)
}

func (s *StaffService) Update(id int, name, lastName, phoneNumber string) (*Staff, error) {
	return s.repo.Update(id, name, lastName, phoneNumber)
}
