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

package db

import (
	"context"
)

const allExitHandlers = `-- name: AllExitHandlers :many
SELECT exithandlers.id as exithandler_id, exhcode,exhdescription,exitpoints.expdescription,exitpoints.expcode,village,parish,districts.name FROM exithandlers
JOIN   exitpoints on exitpoints.id = exithandlers.exitpoint
JOIN   villages  on villages.id    = exitpoints.village_id
JOIN   parishes  on parishes.id    = exitpoints.parish_id
JOIN   districts on districts.id   = exitpoints.district_id
ORDER BY exithandlers.id
`

type AllExitHandlersRow struct {
	ExithandlerID  int64  `json:"exithandler_id"`
	Exhcode        string `json:"exhcode"`
	Exhdescription string `json:"exhdescription"`
	Expdescription string `json:"expdescription"`
	Expcode        string `json:"expcode"`
	Village        string `json:"village"`
	Parish         string `json:"parish"`
	Name           string `json:"name"`
}

func (q *Queries) AllExitHandlers(ctx context.Context) ([]AllExitHandlersRow, error) {
	rows, err := q.db.QueryContext(ctx, allExitHandlers)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AllExitHandlersRow{}
	for rows.Next() {
		var i AllExitHandlersRow
		if err := rows.Scan(
			&i.ExithandlerID,
			&i.Exhcode,
			&i.Exhdescription,
			&i.Expdescription,
			&i.Expcode,
			&i.Village,
			&i.Parish,
			&i.Name,
		); 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 createExitHandler = `-- name: CreateExitHandler :one
INSERT INTO exithandlers (
    exhcode,                                
    exhdescription,
    exitpoint
 ) VALUES (
    $1, $2, $3
 ) RETURNING id, exhcode, exhdescription, exitpoint, status, created_at
`

type CreateExitHandlerParams struct {
	Exhcode        string `json:"exhcode"`
	Exhdescription string `json:"exhdescription"`
	Exitpoint      int32  `json:"exitpoint"`
}

func (q *Queries) CreateExitHandler(ctx context.Context, arg CreateExitHandlerParams) (Exithandler, error) {
	row := q.db.QueryRowContext(ctx, createExitHandler, arg.Exhcode, arg.Exhdescription, arg.Exitpoint)
	var i Exithandler
	err := row.Scan(
		&i.ID,
		&i.Exhcode,
		&i.Exhdescription,
		&i.Exitpoint,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const deleteExitHandler = `-- name: DeleteExitHandler :exec
DELETE FROM exithandlers WHERE id= $1
`

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

const getExitHandler = `-- name: GetExitHandler :one
SELECT id, exhcode, exhdescription, exitpoint, status, created_at FROM exithandlers
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetExitHandler(ctx context.Context, id int64) (Exithandler, error) {
	row := q.db.QueryRowContext(ctx, getExitHandler, id)
	var i Exithandler
	err := row.Scan(
		&i.ID,
		&i.Exhcode,
		&i.Exhdescription,
		&i.Exitpoint,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}

const listExitHanlders = `-- name: ListExitHanlders :many
SELECT id, exhcode, exhdescription, exitpoint, status, created_at FROM exithandlers
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListExitHanlders(ctx context.Context, arg ListExitHanldersParams) ([]Exithandler, error) {
	rows, err := q.db.QueryContext(ctx, listExitHanlders, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Exithandler{}
	for rows.Next() {
		var i Exithandler
		if err := rows.Scan(
			&i.ID,
			&i.Exhcode,
			&i.Exhdescription,
			&i.Exitpoint,
			&i.Status,
			&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 updateExitHandler = `-- name: UpdateExitHandler :one
UPDATE exithandlers
  set 
     exhcode = $2,                                
     exhdescription = $3,
     exitpoint = $4
WHERE id = $1
RETURNING id, exhcode, exhdescription, exitpoint, status, created_at
`

type UpdateExitHandlerParams struct {
	ID             int64  `json:"id"`
	Exhcode        string `json:"exhcode"`
	Exhdescription string `json:"exhdescription"`
	Exitpoint      int32  `json:"exitpoint"`
}

func (q *Queries) UpdateExitHandler(ctx context.Context, arg UpdateExitHandlerParams) (Exithandler, error) {
	row := q.db.QueryRowContext(ctx, updateExitHandler,
		arg.ID,
		arg.Exhcode,
		arg.Exhdescription,
		arg.Exitpoint,
	)
	var i Exithandler
	err := row.Scan(
		&i.ID,
		&i.Exhcode,
		&i.Exhdescription,
		&i.Exitpoint,
		&i.Status,
		&i.CreatedAt,
	)
	return i, err
}
