-- name: GetJob :one
SELECT j.id, j.clientId, coalesce(cs.canSync, false) as canSync
    FROM jobs as j
    LEFT JOIN (
        SELECT jobId, canSync
        FROM jobCanSync
        WHERE jobId = $1
        ORDER BY addedAt DESC
        LIMIT 1
    ) as cs on cs.jobId = j.id
    WHERE j.id = $1;

-- name: CreateJob :one
INSERT INTO jobs (clientId) VALUES ($1) RETURNING id;

-- name: AddJobCanSync :exec
INSERT INTO jobCanSync (canSync, jobId) VALUES ($1, $2);

-- name: ListJobDocumentIDsBatch :many
SELECT id, totalCount FROM listJobDocumentIDs(@jobId, @batchSize, @pageOffset);
