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

package sqlc

import (
	"context"

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

const createBrowserContext = `-- name: CreateBrowserContext :one
INSERT INTO browser_contexts (name, config)
VALUES ($1, $2)
RETURNING id, name, config, created_at, updated_at
`

type CreateBrowserContextParams struct {
	Name   string `json:"name"`
	Config []byte `json:"config"`
}

func (q *Queries) CreateBrowserContext(ctx context.Context, arg CreateBrowserContextParams) (BrowserContext, error) {
	row := q.db.QueryRow(ctx, createBrowserContext, arg.Name, arg.Config)
	var i BrowserContext
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const deleteBrowserContext = `-- name: DeleteBrowserContext :exec
DELETE FROM browser_contexts WHERE id = $1
`

func (q *Queries) DeleteBrowserContext(ctx context.Context, id pgtype.UUID) error {
	_, err := q.db.Exec(ctx, deleteBrowserContext, id)
	return err
}

const getBrowserContextByID = `-- name: GetBrowserContextByID :one
SELECT id, name, config, created_at, updated_at FROM browser_contexts WHERE id = $1
`

func (q *Queries) GetBrowserContextByID(ctx context.Context, id pgtype.UUID) (BrowserContext, error) {
	row := q.db.QueryRow(ctx, getBrowserContextByID, id)
	var i BrowserContext
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const listBrowserContexts = `-- name: ListBrowserContexts :many
SELECT id, name, config, created_at, updated_at FROM browser_contexts ORDER BY created_at DESC
`

func (q *Queries) ListBrowserContexts(ctx context.Context) ([]BrowserContext, error) {
	rows, err := q.db.Query(ctx, listBrowserContexts)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []BrowserContext
	for rows.Next() {
		var i BrowserContext
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.Config,
			&i.CreatedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateBrowserContext = `-- name: UpdateBrowserContext :one
UPDATE browser_contexts
SET name = $1,
    config = $2,
    updated_at = now()
WHERE id = $3
RETURNING id, name, config, created_at, updated_at
`

type UpdateBrowserContextParams struct {
	Name   string      `json:"name"`
	Config []byte      `json:"config"`
	ID     pgtype.UUID `json:"id"`
}

func (q *Queries) UpdateBrowserContext(ctx context.Context, arg UpdateBrowserContextParams) (BrowserContext, error) {
	row := q.db.QueryRow(ctx, updateBrowserContext, arg.Name, arg.Config, arg.ID)
	var i BrowserContext
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}
