package access

import (
	"fmt"
	"strings"
)

func Validate(req ClosureRequest) error {
	switch strings.TrimSpace(req.Mode) {
	case ModeSubscription:
		if len(req.Subscriptions) == 0 {
			return fmt.Errorf("subscription access requires at least one subscription target")
		}
	case ModeSelfService:
		if selfServiceProbeAPIKey(req) == "" {
			return fmt.Errorf("self_service access requires probe api key")
		}
	default:
		return fmt.Errorf("unsupported access mode %q", req.Mode)
	}
	if strings.TrimSpace(req.Mode) != ModeSubscription && selfServiceProbeAPIKey(req) == "" {
		return fmt.Errorf("access probe api key is required to verify gateway closure")
	}
	return nil
}
