package app

import (
	"context"
	"fmt"

	"github.com/tidbcloud/AgentTeam/internal/coredb"
	"github.com/tidbcloud/AgentTeam/internal/store/plan"
)

func (store *Store) checkWorkspaceQuotaInTx(ctx context.Context, tx coredb.Tx, workspaceID string, metric plan.MetricKey, delta int64) error {
	if store == nil || store.options.CheckWorkspaceQuotaInTx == nil {
		return fmt.Errorf("app store quota checker is not configured")
	}
	return store.options.CheckWorkspaceQuotaInTx(ctx, tx, workspaceID, metric, delta)
}

func (store *Store) checkWorkspaceAgentOwnerQuotaInTx(ctx context.Context, tx coredb.Tx, workspaceID string, ownerUserID string, delta int64) error {
	if store == nil || store.options.CheckWorkspaceAgentOwnerQuotaInTx == nil {
		return fmt.Errorf("app store agent owner quota checker is not configured")
	}
	return store.options.CheckWorkspaceAgentOwnerQuotaInTx(ctx, tx, workspaceID, ownerUserID, delta)
}
