// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.27.0
// source: flow_templates.sql

package database

import (
	"context"
)

const createFlowTemplate = `-- name: CreateFlowTemplate :one
INSERT INTO flow_templates (
  user_id,
  title,
  text
) VALUES (
  $1,
  $2,
  $3
)
RETURNING id, user_id, title, text, created_at, updated_at
`

type CreateFlowTemplateParams struct {
	UserID int64  `json:"user_id"`
	Title  string `json:"title"`
	Text   string `json:"text"`
}

func (q *Queries) CreateFlowTemplate(ctx context.Context, arg CreateFlowTemplateParams) (FlowTemplate, error) {
	row := q.db.QueryRowContext(ctx, createFlowTemplate, arg.UserID, arg.Title, arg.Text)
	var i FlowTemplate
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Title,
		&i.Text,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const deleteFlowTemplate = `-- name: DeleteFlowTemplate :exec
DELETE FROM flow_templates
WHERE id = $1 AND user_id = $2
`

type DeleteFlowTemplateParams struct {
	ID     int64 `json:"id"`
	UserID int64 `json:"user_id"`
}

func (q *Queries) DeleteFlowTemplate(ctx context.Context, arg DeleteFlowTemplateParams) error {
	_, err := q.db.ExecContext(ctx, deleteFlowTemplate, arg.ID, arg.UserID)
	return err
}

const getFlowTemplate = `-- name: GetFlowTemplate :one
SELECT id, user_id, title, text, created_at, updated_at FROM flow_templates
WHERE id = $1 AND user_id = $2 LIMIT 1
`

type GetFlowTemplateParams struct {
	ID     int64 `json:"id"`
	UserID int64 `json:"user_id"`
}

func (q *Queries) GetFlowTemplate(ctx context.Context, arg GetFlowTemplateParams) (FlowTemplate, error) {
	row := q.db.QueryRowContext(ctx, getFlowTemplate, arg.ID, arg.UserID)
	var i FlowTemplate
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Title,
		&i.Text,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const getFlowTemplatesByUserID = `-- name: GetFlowTemplatesByUserID :many
SELECT id, user_id, title, text, created_at, updated_at FROM flow_templates
WHERE user_id = $1
ORDER BY created_at DESC
`

func (q *Queries) GetFlowTemplatesByUserID(ctx context.Context, userID int64) ([]FlowTemplate, error) {
	rows, err := q.db.QueryContext(ctx, getFlowTemplatesByUserID, userID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []FlowTemplate
	for rows.Next() {
		var i FlowTemplate
		if err := rows.Scan(
			&i.ID,
			&i.UserID,
			&i.Title,
			&i.Text,
			&i.CreatedAt,
			&i.UpdatedAt,
		); 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 updateFlowTemplate = `-- name: UpdateFlowTemplate :one
UPDATE flow_templates
SET 
  title = $3,
  text = $4
WHERE id = $1 AND user_id = $2
RETURNING id, user_id, title, text, created_at, updated_at
`

type UpdateFlowTemplateParams struct {
	ID     int64  `json:"id"`
	UserID int64  `json:"user_id"`
	Title  string `json:"title"`
	Text   string `json:"text"`
}

func (q *Queries) UpdateFlowTemplate(ctx context.Context, arg UpdateFlowTemplateParams) (FlowTemplate, error) {
	row := q.db.QueryRowContext(ctx, updateFlowTemplate,
		arg.ID,
		arg.UserID,
		arg.Title,
		arg.Text,
	)
	var i FlowTemplate
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Title,
		&i.Text,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}
