// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.28.0
// source: reception_documents.sql

package db

import (
	"context"
	"database/sql"
	"time"
)

const createReceptionDocument = `-- name: CreateReceptionDocument :one
INSERT INTO reception_documents (   
    document_id,        
    document,
    receptionform_id
 ) VALUES (
    $1,
    $2,
    $3
) 
RETURNING id, receptionform_id, description, created_at, document_id, document
`

type CreateReceptionDocumentParams struct {
	DocumentID      int32  `json:"document_id"`
	Document        string `json:"document"`
	ReceptionformID int32  `json:"receptionform_id"`
}

func (q *Queries) CreateReceptionDocument(ctx context.Context, arg CreateReceptionDocumentParams) (ReceptionDocument, error) {
	row := q.db.QueryRowContext(ctx, createReceptionDocument, arg.DocumentID, arg.Document, arg.ReceptionformID)
	var i ReceptionDocument
	err := row.Scan(
		&i.ID,
		&i.ReceptionformID,
		&i.Description,
		&i.CreatedAt,
		&i.DocumentID,
		&i.Document,
	)
	return i, err
}

const deleteReceptionDocument = `-- name: DeleteReceptionDocument :exec
DELETE FROM reception_documents WHERE id= $1
`

func (q *Queries) DeleteReceptionDocument(ctx context.Context, id int64) error {
	_, err := q.db.ExecContext(ctx, deleteReceptionDocument, id)
	return err
}

const getReceptionFormDocument = `-- 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
`

type GetReceptionFormDocumentRow struct {
	ReceptionformID int32     `json:"receptionform_id"`
	Description     string    `json:"description"`
	DocumentID      int64     `json:"document_id"`
	CreatedAt       time.Time `json:"created_at"`
	Document        string    `json:"document"`
	Name            string    `json:"name"`
	Documentusage   string    `json:"documentusage"`
	ReceptiondocID  int64     `json:"receptiondoc_id"`
}

func (q *Queries) GetReceptionFormDocument(ctx context.Context, receptionformID int32) ([]GetReceptionFormDocumentRow, error) {
	rows, err := q.db.QueryContext(ctx, getReceptionFormDocument, receptionformID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetReceptionFormDocumentRow{}
	for rows.Next() {
		var i GetReceptionFormDocumentRow
		if err := rows.Scan(
			&i.ReceptionformID,
			&i.Description,
			&i.DocumentID,
			&i.CreatedAt,
			&i.Document,
			&i.Name,
			&i.Documentusage,
			&i.ReceptiondocID,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const listReceptionDocuments = `-- name: ListReceptionDocuments :many
SELECT id, receptionform_id, description, created_at, document_id, document FROM reception_documents
ORDER BY id LIMIT $1
OFFSET $2
`

type ListReceptionDocumentsParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

func (q *Queries) ListReceptionDocuments(ctx context.Context, arg ListReceptionDocumentsParams) ([]ReceptionDocument, error) {
	rows, err := q.db.QueryContext(ctx, listReceptionDocuments, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ReceptionDocument{}
	for rows.Next() {
		var i ReceptionDocument
		if err := rows.Scan(
			&i.ID,
			&i.ReceptionformID,
			&i.Description,
			&i.CreatedAt,
			&i.DocumentID,
			&i.Document,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateReceptionDocument = `-- name: UpdateReceptionDocument :one
UPDATE reception_documents
  set 
    document  = $1,
    receptionform_id   = $2
WHERE id = $3
RETURNING id, receptionform_id, description, created_at, document_id, document
`

type UpdateReceptionDocumentParams struct {
	Document        sql.NullString `json:"document"`
	ReceptionformID sql.NullInt32  `json:"receptionform_id"`
	ID              sql.NullInt64  `json:"id"`
}

func (q *Queries) UpdateReceptionDocument(ctx context.Context, arg UpdateReceptionDocumentParams) (ReceptionDocument, error) {
	row := q.db.QueryRowContext(ctx, updateReceptionDocument, arg.Document, arg.ReceptionformID, arg.ID)
	var i ReceptionDocument
	err := row.Scan(
		&i.ID,
		&i.ReceptionformID,
		&i.Description,
		&i.CreatedAt,
		&i.DocumentID,
		&i.Document,
	)
	return i, err
}
