package staffrepository

import (
	"errors"

	authdomain "legalgo-BE-go/internal/domain/auth"

	"gorm.io/gorm"
)

func (sr *StaffRepository) GetStaffByEmail(email string) (*authdomain.Staff, error) {
	var staff authdomain.Staff

	if email == "" {
		return nil, errors.New("email is required")
	}

	if err := sr.DB.First(&staff, "email = ?", email).Error; err != nil {
		if errors.Is(err, gorm.ErrRecordNotFound) {
			return nil, errors.New("staff not found")
		}
		return nil, err
	}

	return &staff, nil
}
