// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.31.1
// source: templates.sql

package chatsqlc

import (
	"context"

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

const deletePromptTemplate = `-- name: DeletePromptTemplate :exec
DELETE FROM prompt_templates WHERE id = $1
`

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

const getPromptTemplate = `-- name: GetPromptTemplate :one
SELECT id, name, content, scope, owner_id, created_at, updated_at FROM prompt_templates WHERE id = $1
`

func (q *Queries) GetPromptTemplate(ctx context.Context, id pgtype.UUID) (PromptTemplate, error) {
	row := q.db.QueryRow(ctx, getPromptTemplate, id)
	var i PromptTemplate
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Content,
		&i.Scope,
		&i.OwnerID,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const insertPromptTemplate = `-- name: InsertPromptTemplate :one
INSERT INTO prompt_templates (id, name, content, scope, owner_id)
VALUES ($1, $2, $3, $4, $5)
RETURNING id, name, content, scope, owner_id, created_at, updated_at
`

type InsertPromptTemplateParams struct {
	ID      pgtype.UUID `json:"id"`
	Name    string      `json:"name"`
	Content string      `json:"content"`
	Scope   string      `json:"scope"`
	OwnerID pgtype.UUID `json:"owner_id"`
}

func (q *Queries) InsertPromptTemplate(ctx context.Context, arg InsertPromptTemplateParams) (PromptTemplate, error) {
	row := q.db.QueryRow(ctx, insertPromptTemplate,
		arg.ID,
		arg.Name,
		arg.Content,
		arg.Scope,
		arg.OwnerID,
	)
	var i PromptTemplate
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Content,
		&i.Scope,
		&i.OwnerID,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const listPromptTemplatesForUser = `-- name: ListPromptTemplatesForUser :many
SELECT id, name, content, scope, owner_id, created_at, updated_at FROM prompt_templates
WHERE scope = 'system' OR (scope = 'user' AND owner_id = $1)
ORDER BY scope, name
`

func (q *Queries) ListPromptTemplatesForUser(ctx context.Context, ownerID pgtype.UUID) ([]PromptTemplate, error) {
	rows, err := q.db.Query(ctx, listPromptTemplatesForUser, ownerID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []PromptTemplate
	for rows.Next() {
		var i PromptTemplate
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.Content,
			&i.Scope,
			&i.OwnerID,
			&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 updatePromptTemplate = `-- name: UpdatePromptTemplate :exec
UPDATE prompt_templates SET name = $2, content = $3, updated_at = NOW()
WHERE id = $1
`

type UpdatePromptTemplateParams struct {
	ID      pgtype.UUID `json:"id"`
	Name    string      `json:"name"`
	Content string      `json:"content"`
}

func (q *Queries) UpdatePromptTemplate(ctx context.Context, arg UpdatePromptTemplateParams) error {
	_, err := q.db.Exec(ctx, updatePromptTemplate, arg.ID, arg.Name, arg.Content)
	return err
}
