package subscriberepository

import (
	"errors"
	"fmt"
	subscribedomain "legalgo-BE-go/internal/domain/subscribe"

	"gorm.io/gorm"
)

func (s *accessor) GetByID(id string) (subscribedomain.Subscribe, error) {
	var subscribe subscribedomain.Subscribe

	if err := s.db.First(&subscribe, "id = ?", id).Error; err != nil {
		if errors.Is(err, gorm.ErrRecordNotFound) {
			return subscribe, fmt.Errorf("subscribe data not found: %v", err)
		}

		return subscribe, err
	}

	return subscribe, nil
}
