package gorules

import (
	"context"
	"errors"
	"time"
	"tm/pkg/logger"

	// "repo.ravanertebat.com/k.khodayari/gorulessdk" // temporarily disabled: private repo unreachable from server
)

/*
const (
	showAvailableStatusAction = gorulessdk.ShowAvailableStatus
)
*/

// Config contains GoRules client configuration.
type Config struct {
	BaseURL string
	Token   string
	Timeout time.Duration
}

// StatusWithCategory contains status and category values returned by GoRules.
type StatusWithCategory struct {
	Status         string `json:"status"`
	StatusCategory string `json:"status_category"`
}

// Client evaluates available statuses against GoRules.
type Client interface {
	EvaluateAvailableStatuses(ctx context.Context, currentStatus string, ruleID string) ([]StatusWithCategory, error)
}

// New creates a new GoRules client.
// Temporarily disabled: gorulessdk is unavailable from the deployment server.
func New(_ Config, _ logger.Logger) (Client, error) {
	return nil, errors.New("gorulessdk temporarily disabled")
}

/*
type sdkClient struct {
	client *gorulessdk.Client
	logger logger.Logger
}

func New(cfg Config, log logger.Logger) (Client, error) {
	if strings.TrimSpace(cfg.BaseURL) == "" {
		return nil, errors.New("gorules base url is required")
	}
	if strings.TrimSpace(cfg.Token) == "" {
		return nil, errors.New("gorules token is required")
	}

	timeout := cfg.Timeout
	if timeout <= 0 {
		timeout = 10 * time.Second
	}

	client, err := gorulessdk.NewClient(cfg.BaseURL, cfg.Token, gorulessdk.WithTimeout(timeout))
	if err != nil {
		return nil, err
	}

	return &sdkClient{
		client: client,
		logger: log,
	}, nil
}

func (s *sdkClient) EvaluateAvailableStatuses(ctx context.Context, currentStatus string, ruleID string) ([]StatusWithCategory, error) {
	input := gorulessdk.Input{
		Status: currentStatus,
		Action: showAvailableStatusAction,
	}

	resp, err := s.client.Evaluate(ctx, ruleID, &input)
	if err != nil {
		return nil, err
	}

	available := resp.AvailableStatuses()
	statuses := make([]StatusWithCategory, 0, len(available))
	for _, item := range available {
		statuses = append(statuses, StatusWithCategory{
			Status:         item.Status,
			StatusCategory: item.Category,
		})
	}
	return statuses, nil
}
*/
