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

package db

import (
	"context"
)

const createConsignmentReasonRejection = `-- name: CreateConsignmentReasonRejection :one
INSERT INTO consignmentreasonrejections (
    crrcode,
    crrdescription
 ) VALUES (
    $1, $2
 ) RETURNING id, crrcode, crrdescription, created_at
`

type CreateConsignmentReasonRejectionParams struct {
	Crrcode        string `json:"crrcode"`
	Crrdescription string `json:"crrdescription"`
}

func (q *Queries) CreateConsignmentReasonRejection(ctx context.Context, arg CreateConsignmentReasonRejectionParams) (Consignmentreasonrejection, error) {
	row := q.db.QueryRowContext(ctx, createConsignmentReasonRejection, arg.Crrcode, arg.Crrdescription)
	var i Consignmentreasonrejection
	err := row.Scan(
		&i.ID,
		&i.Crrcode,
		&i.Crrdescription,
		&i.CreatedAt,
	)
	return i, err
}

const deleteConsignmentReasonRejection = `-- name: DeleteConsignmentReasonRejection :exec
DELETE FROM consignmentreasonrejections WHERE id= $1
`

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

const getConsignmentReasonRejection = `-- name: GetConsignmentReasonRejection :one
SELECT id, crrcode, crrdescription, created_at FROM consignmentreasonrejections
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetConsignmentReasonRejection(ctx context.Context, id int64) (Consignmentreasonrejection, error) {
	row := q.db.QueryRowContext(ctx, getConsignmentReasonRejection, id)
	var i Consignmentreasonrejection
	err := row.Scan(
		&i.ID,
		&i.Crrcode,
		&i.Crrdescription,
		&i.CreatedAt,
	)
	return i, err
}

const listConsignmentReasonRejections = `-- name: ListConsignmentReasonRejections :many
SELECT id, crrcode, crrdescription, created_at FROM consignmentreasonrejections
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListConsignmentReasonRejections(ctx context.Context, arg ListConsignmentReasonRejectionsParams) ([]Consignmentreasonrejection, error) {
	rows, err := q.db.QueryContext(ctx, listConsignmentReasonRejections, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Consignmentreasonrejection{}
	for rows.Next() {
		var i Consignmentreasonrejection
		if err := rows.Scan(
			&i.ID,
			&i.Crrcode,
			&i.Crrdescription,
			&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 updateConsignmentReasonRejection = `-- name: UpdateConsignmentReasonRejection :one
UPDATE consignmentreasonrejections
  set 
    crrcode= $2,
    crrdescription = $3
WHERE id = $1
RETURNING id, crrcode, crrdescription, created_at
`

type UpdateConsignmentReasonRejectionParams struct {
	ID             int64  `json:"id"`
	Crrcode        string `json:"crrcode"`
	Crrdescription string `json:"crrdescription"`
}

func (q *Queries) UpdateConsignmentReasonRejection(ctx context.Context, arg UpdateConsignmentReasonRejectionParams) (Consignmentreasonrejection, error) {
	row := q.db.QueryRowContext(ctx, updateConsignmentReasonRejection, arg.ID, arg.Crrcode, arg.Crrdescription)
	var i Consignmentreasonrejection
	err := row.Scan(
		&i.ID,
		&i.Crrcode,
		&i.Crrdescription,
		&i.CreatedAt,
	)
	return i, err
}
