-- name: ListCollectorQueries :many
SELECT clientId, queryId, queryType, queryVersion, requiredIds
        FROM collectorQueryDependencyTreeByClient(@clientId);

-- name: GetCollectorByClientID :one
SELECT * FROM fullActiveCollectors WHERE clientId = @clientId LIMIT 1;

-- name: AddLatestCollectorVersion :one
INSERT INTO collectorVersions (clientId) VALUES ($1) RETURNING id;

-- name: SetActiveCollectorVersion :exec
INSERT INTO collectorActiveVersions (clientId, versionId) VALUES ($1, $2);

-- name: SetCollectorCleanVersion :exec
INSERT INTO collectorMinCleanVersions (clientId, addedVersion, versionId) VALUES ($1, $2, $3);

-- name: SetCollectorTextVersion :exec
INSERT INTO collectorMinTextVersions (clientId, addedVersion, versionId) VALUES ($1, $2, $3);

-- name: AddCollectorQuery :exec
INSERT INTO collectorQueries (clientId, name, queryId, addedVersion) VALUES ($1, $2, $3, $4);

-- name: RemoveCollectorQuery :exec
UPDATE collectorQueries SET removedVersion = $1 WHERE queryId = $2 and clientId = $3 and removedVersion is null;
