package access

import (
	"context"
	"fmt"

	"sub2api-cn-relay-manager/internal/host/sub2api"
)

func (s *Service) Close(ctx context.Context, req ClosureRequest) (sub2api.GatewayAccessResult, error) {
	if s == nil || s.host == nil {
		return sub2api.GatewayAccessResult{}, fmt.Errorf("access host is required")
	}
	if err := Validate(req); err != nil {
		return sub2api.GatewayAccessResult{}, err
	}

	plan, err := s.prepareClosurePlan(ctx, req)
	if err != nil {
		return sub2api.GatewayAccessResult{}, err
	}
	return s.verifyGatewayClosure(ctx, req, plan)
}
