-- name: CreateReceptionDocument :one
INSERT INTO reception_documents (   
    document_id,        
    document,
    receptionform_id
 ) VALUES (
    $1,
    $2,
    $3
) 
RETURNING *;

 -- name: GetReceptionDocument :one
SELECT * FROM reception_documents
WHERE receptionform_id = $1 LIMIT 1;

-- name: ListReceptionDocuments :many
SELECT * FROM reception_documents
ORDER BY id LIMIT $1
OFFSET $2;

-- name: UpdateReceptionDocument :one
UPDATE reception_documents
  set 
    document  = sqlc.narg(document),
    receptionform_id   = sqlc.narg(receptionform_id)
WHERE id = sqlc.narg(id)
RETURNING *;

-- name: DeleteReceptionDocument :exec
DELETE FROM reception_documents WHERE id= $1;

-- name: GetReceptionFormDocument :many
SELECT reception_documents.receptionform_id,documents.description,documents.id document_id,
reception_documents.created_at,reception_documents.document,documents.name,
documents.documentusage, reception_documents.id as receptiondoc_id FROM reception_documents
JOIN  documents on documents.id = reception_documents.document_id
WHERE receptionform_id = $1;