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

package db

import (
	"context"
)

const createPackageType = `-- name: CreatePackageType :one
INSERT INTO packagetypes (
    pgcode,
    pgdescription
 ) VALUES (
    $1, $2
 ) RETURNING id, pgcode, pgdescription, created_at
`

type CreatePackageTypeParams struct {
	Pgcode        string `json:"pgcode"`
	Pgdescription string `json:"pgdescription"`
}

func (q *Queries) CreatePackageType(ctx context.Context, arg CreatePackageTypeParams) (Packagetype, error) {
	row := q.db.QueryRowContext(ctx, createPackageType, arg.Pgcode, arg.Pgdescription)
	var i Packagetype
	err := row.Scan(
		&i.ID,
		&i.Pgcode,
		&i.Pgdescription,
		&i.CreatedAt,
	)
	return i, err
}

const deletePackageType = `-- name: DeletePackageType :exec
DELETE FROM packagetypes WHERE id= $1
`

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

const getPackageType = `-- name: GetPackageType :one
SELECT id, pgcode, pgdescription, created_at FROM packagetypes
WHERE id = $1 LIMIT 1
`

func (q *Queries) GetPackageType(ctx context.Context, id int64) (Packagetype, error) {
	row := q.db.QueryRowContext(ctx, getPackageType, id)
	var i Packagetype
	err := row.Scan(
		&i.ID,
		&i.Pgcode,
		&i.Pgdescription,
		&i.CreatedAt,
	)
	return i, err
}

const listPackageTypes = `-- name: ListPackageTypes :many
SELECT id, pgcode, pgdescription, created_at FROM packagetypes
ORDER BY id LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListPackageTypes(ctx context.Context, arg ListPackageTypesParams) ([]Packagetype, error) {
	rows, err := q.db.QueryContext(ctx, listPackageTypes, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Packagetype{}
	for rows.Next() {
		var i Packagetype
		if err := rows.Scan(
			&i.ID,
			&i.Pgcode,
			&i.Pgdescription,
			&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 updatePackageType = `-- name: UpdatePackageType :one
UPDATE packagetypes
  set 
    pgcode= $2,
    pgdescription= $3
WHERE id = $1
RETURNING id, pgcode, pgdescription, created_at
`

type UpdatePackageTypeParams struct {
	ID            int64  `json:"id"`
	Pgcode        string `json:"pgcode"`
	Pgdescription string `json:"pgdescription"`
}

func (q *Queries) UpdatePackageType(ctx context.Context, arg UpdatePackageTypeParams) (Packagetype, error) {
	row := q.db.QueryRowContext(ctx, updatePackageType, arg.ID, arg.Pgcode, arg.Pgdescription)
	var i Packagetype
	err := row.Scan(
		&i.ID,
		&i.Pgcode,
		&i.Pgdescription,
		&i.CreatedAt,
	)
	return i, err
}
