package staffrepository

import (
	"errors"
	"fmt"

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

	"gorm.io/gorm"
)

func (sr *accessor) GetStaffByEmail(email string) (*staffdomain.Staff, error) {
	var staff staffdomain.Staff

	if email == "" {
		return nil, fmt.Errorf("email is required")
	}

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

	return &staff, nil
}
