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

package db

import (
	"context"
)

const checkDocumentCode = `-- name: CheckDocumentCode :one
SELECT EXISTS (
    SELECT 1 
    FROM document_codes 
    WHERE dccode = $1
) AS record_exists
`

func (q *Queries) CheckDocumentCode(ctx context.Context, dccode string) (bool, error) {
	row := q.db.QueryRowContext(ctx, checkDocumentCode, dccode)
	var record_exists bool
	err := row.Scan(&record_exists)
	return record_exists, err
}

const createDocumentCode = `-- name: CreateDocumentCode :one
INSERT INTO document_codes (
    dccode
 ) VALUES (
    $1
 ) RETURNING id, dccode, created_at, updated_at
`

func (q *Queries) CreateDocumentCode(ctx context.Context, dccode string) (DocumentCode, error) {
	row := q.db.QueryRowContext(ctx, createDocumentCode, dccode)
	var i DocumentCode
	err := row.Scan(
		&i.ID,
		&i.Dccode,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const getDocumentByCode = `-- name: GetDocumentByCode :one
SELECT id, dccode, created_at, updated_at FROM document_codes
WHERE dccode = $1 LIMIT 1
`

func (q *Queries) GetDocumentByCode(ctx context.Context, dccode string) (DocumentCode, error) {
	row := q.db.QueryRowContext(ctx, getDocumentByCode, dccode)
	var i DocumentCode
	err := row.Scan(
		&i.ID,
		&i.Dccode,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const searchDocumentCode = `-- name: SearchDocumentCode :many
SELECT id, dccode, created_at, updated_at FROM document_codes
WHERE LOWER(dccode) LIKE '%' || LOWER($1) || '%'
`

func (q *Queries) SearchDocumentCode(ctx context.Context, lower string) ([]DocumentCode, error) {
	rows, err := q.db.QueryContext(ctx, searchDocumentCode, lower)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []DocumentCode{}
	for rows.Next() {
		var i DocumentCode
		if err := rows.Scan(
			&i.ID,
			&i.Dccode,
			&i.CreatedAt,
			&i.UpdatedAt,
		); 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
}
