package staffrepository

import (
	"errors"
	"fmt"
	staffdomain "legalgo-BE-go/internal/domain/staff"

	"gorm.io/gorm"
)

func (sr *accessor) GetStaffByID(ID string) (*staffdomain.Staff, error) {
	var staff staffdomain.Staff

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

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

	return &staff, nil
}
