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

package db

import (
	"context"

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

const countRecentFeedbackByUser = `-- name: CountRecentFeedbackByUser :one
SELECT count(*) FROM feedback
WHERE user_id = $1 AND created_at > now() - interval '1 hour'
`

func (q *Queries) CountRecentFeedbackByUser(ctx context.Context, userID pgtype.UUID) (int64, error) {
	row := q.db.QueryRow(ctx, countRecentFeedbackByUser, userID)
	var count int64
	err := row.Scan(&count)
	return count, err
}

const createFeedback = `-- name: CreateFeedback :one
INSERT INTO feedback (user_id, workspace_id, message, metadata)
VALUES ($1, $4, $2, $3)
RETURNING id, user_id, workspace_id, message, metadata, created_at
`

type CreateFeedbackParams struct {
	UserID      pgtype.UUID `json:"user_id"`
	Message     string      `json:"message"`
	Metadata    []byte      `json:"metadata"`
	WorkspaceID pgtype.UUID `json:"workspace_id"`
}

func (q *Queries) CreateFeedback(ctx context.Context, arg CreateFeedbackParams) (Feedback, error) {
	row := q.db.QueryRow(ctx, createFeedback,
		arg.UserID,
		arg.Message,
		arg.Metadata,
		arg.WorkspaceID,
	)
	var i Feedback
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.WorkspaceID,
		&i.Message,
		&i.Metadata,
		&i.CreatedAt,
	)
	return i, err
}
