// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.30.0
// source: course_catagories.sql

package dbgen

import (
	"context"

	"github.com/jackc/pgx/v5/pgtype"
)

const CreateCourseCategory = `-- name: CreateCourseCategory :one
INSERT INTO course_categories (
    name,
    is_active
)
VALUES ($1, COALESCE($2, true))
RETURNING id, name, is_active, created_at
`

type CreateCourseCategoryParams struct {
	Name    string      `json:"name"`
	Column2 interface{} `json:"column_2"`
}

func (q *Queries) CreateCourseCategory(ctx context.Context, arg CreateCourseCategoryParams) (CourseCategory, error) {
	row := q.db.QueryRow(ctx, CreateCourseCategory, arg.Name, arg.Column2)
	var i CourseCategory
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.IsActive,
		&i.CreatedAt,
	)
	return i, err
}

const DeleteCourseCategory = `-- name: DeleteCourseCategory :exec
DELETE FROM course_categories
WHERE id = $1
`

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

const GetAllCourseCategories = `-- name: GetAllCourseCategories :many
SELECT
    COUNT(*) OVER () AS total_count,
    id,
    name,
    is_active,
    created_at
FROM course_categories
ORDER BY created_at DESC
LIMIT $2::INT
OFFSET $1::INT
`

type GetAllCourseCategoriesParams struct {
	Offset pgtype.Int4 `json:"offset"`
	Limit  pgtype.Int4 `json:"limit"`
}

type GetAllCourseCategoriesRow struct {
	TotalCount int64              `json:"total_count"`
	ID         int64              `json:"id"`
	Name       string             `json:"name"`
	IsActive   bool               `json:"is_active"`
	CreatedAt  pgtype.Timestamptz `json:"created_at"`
}

func (q *Queries) GetAllCourseCategories(ctx context.Context, arg GetAllCourseCategoriesParams) ([]GetAllCourseCategoriesRow, error) {
	rows, err := q.db.Query(ctx, GetAllCourseCategories, arg.Offset, arg.Limit)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []GetAllCourseCategoriesRow
	for rows.Next() {
		var i GetAllCourseCategoriesRow
		if err := rows.Scan(
			&i.TotalCount,
			&i.ID,
			&i.Name,
			&i.IsActive,
			&i.CreatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const GetCourseCategoryByID = `-- name: GetCourseCategoryByID :one
SELECT id, name, is_active, created_at
FROM course_categories
WHERE id = $1
`

func (q *Queries) GetCourseCategoryByID(ctx context.Context, id int64) (CourseCategory, error) {
	row := q.db.QueryRow(ctx, GetCourseCategoryByID, id)
	var i CourseCategory
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.IsActive,
		&i.CreatedAt,
	)
	return i, err
}

const UpdateCourseCategory = `-- name: UpdateCourseCategory :exec
UPDATE course_categories
SET
    name = COALESCE($1, name),
    is_active = COALESCE($2, is_active)
WHERE id = $3
`

type UpdateCourseCategoryParams struct {
	Name     string `json:"name"`
	IsActive bool   `json:"is_active"`
	ID       int64  `json:"id"`
}

func (q *Queries) UpdateCourseCategory(ctx context.Context, arg UpdateCourseCategoryParams) error {
	_, err := q.db.Exec(ctx, UpdateCourseCategory, arg.Name, arg.IsActive, arg.ID)
	return err
}
