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

package db

import (
	"context"
)

const createDocumentType = `-- name: CreateDocumentType :one
INSERT INTO consignmentdoctypes (
    cdcode,
    cddescription
 ) VALUES (
    $1, $2
 ) RETURNING id, cdcode, cddescription, created_at
`

type CreateDocumentTypeParams struct {
	Cdcode        string `json:"cdcode"`
	Cddescription string `json:"cddescription"`
}

func (q *Queries) CreateDocumentType(ctx context.Context, arg CreateDocumentTypeParams) (Consignmentdoctype, error) {
	row := q.db.QueryRowContext(ctx, createDocumentType, arg.Cdcode, arg.Cddescription)
	var i Consignmentdoctype
	err := row.Scan(
		&i.ID,
		&i.Cdcode,
		&i.Cddescription,
		&i.CreatedAt,
	)
	return i, err
}

const deleteDocumentType = `-- name: DeleteDocumentType :exec
DELETE FROM consignmentdoctypes WHERE id= $1
`

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

const getDocumentType = `-- name: GetDocumentType :one
SELECT id, cdcode, cddescription, created_at FROM consignmentdoctypes
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetDocumentType(ctx context.Context, id int64) (Consignmentdoctype, error) {
	row := q.db.QueryRowContext(ctx, getDocumentType, id)
	var i Consignmentdoctype
	err := row.Scan(
		&i.ID,
		&i.Cdcode,
		&i.Cddescription,
		&i.CreatedAt,
	)
	return i, err
}

const listDocumentTypes = `-- name: ListDocumentTypes :many
SELECT id, cdcode, cddescription, created_at FROM consignmentdoctypes
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListDocumentTypes(ctx context.Context, arg ListDocumentTypesParams) ([]Consignmentdoctype, error) {
	rows, err := q.db.QueryContext(ctx, listDocumentTypes, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Consignmentdoctype{}
	for rows.Next() {
		var i Consignmentdoctype
		if err := rows.Scan(
			&i.ID,
			&i.Cdcode,
			&i.Cddescription,
			&i.CreatedAt,
		); 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 updateDocumentType = `-- name: UpdateDocumentType :one
UPDATE consignmentdoctypes
  set 
    cdcode= $2,
    cddescription = $3
WHERE id = $1
RETURNING id, cdcode, cddescription, created_at
`

type UpdateDocumentTypeParams struct {
	ID            int64  `json:"id"`
	Cdcode        string `json:"cdcode"`
	Cddescription string `json:"cddescription"`
}

func (q *Queries) UpdateDocumentType(ctx context.Context, arg UpdateDocumentTypeParams) (Consignmentdoctype, error) {
	row := q.db.QueryRowContext(ctx, updateDocumentType, arg.ID, arg.Cdcode, arg.Cddescription)
	var i Consignmentdoctype
	err := row.Scan(
		&i.ID,
		&i.Cdcode,
		&i.Cddescription,
		&i.CreatedAt,
	)
	return i, err
}
