package subscribeplanrepository

import (
	"errors"
	"fmt"
	subscribeplandomain "legalgo-BE-go/internal/domain/subscribe_plan"

	"gorm.io/gorm"
)

func (s *accessor) GetByID(id string) (*subscribeplandomain.SubscribePlan, error) {
	var subscribePlan *subscribeplandomain.SubscribePlan

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

	return subscribePlan, nil
}
