package staffrepository

import (
	"errors"

	staffdomain "legalgo-BE-go/internal/domain/staff"

	"gorm.io/gorm"
)

func (sr *impl) GetStaffByEmail(email string) (*staffdomain.Staff, error) {
	var staff staffdomain.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
}
