// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: query.sql

package sqlc

import (
	"context"
)

const getCommentByID = `-- name: GetCommentByID :one
SELECT id, user_id, sku, text, created_at FROM comments WHERE id = $1
`

func (q *Queries) GetCommentByID(ctx context.Context, id int64) (*Comment, error) {
	row := q.db.QueryRow(ctx, getCommentByID, id)
	var i Comment
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Sku,
		&i.Text,
		&i.CreatedAt,
	)
	return &i, err
}

const insertComment = `-- name: InsertComment :one
INSERT INTO comments (id, user_id, sku, text) VALUES ($1, $2, $3, $4)
RETURNING id, user_id, sku, text, created_at
`

type InsertCommentParams struct {
	ID     int64
	UserID int64
	Sku    int64
	Text   string
}

func (q *Queries) InsertComment(ctx context.Context, arg *InsertCommentParams) (*Comment, error) {
	row := q.db.QueryRow(ctx, insertComment,
		arg.ID,
		arg.UserID,
		arg.Sku,
		arg.Text,
	)
	var i Comment
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Sku,
		&i.Text,
		&i.CreatedAt,
	)
	return &i, err
}

const listCommentsBySku = `-- name: ListCommentsBySku :many
SELECT id, user_id, sku, text, created_at
FROM comments
WHERE sku = $1
ORDER BY created_at DESC, user_id ASC
`

func (q *Queries) ListCommentsBySku(ctx context.Context, sku int64) ([]*Comment, error) {
	rows, err := q.db.Query(ctx, listCommentsBySku, sku)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []*Comment
	for rows.Next() {
		var i Comment
		if err := rows.Scan(
			&i.ID,
			&i.UserID,
			&i.Sku,
			&i.Text,
			&i.CreatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, &i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const listCommentsByUser = `-- name: ListCommentsByUser :many
SELECT id, user_id, sku, text, created_at
FROM comments
WHERE user_id = $1
ORDER BY created_at DESC
`

func (q *Queries) ListCommentsByUser(ctx context.Context, userID int64) ([]*Comment, error) {
	rows, err := q.db.Query(ctx, listCommentsByUser, userID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []*Comment
	for rows.Next() {
		var i Comment
		if err := rows.Scan(
			&i.ID,
			&i.UserID,
			&i.Sku,
			&i.Text,
			&i.CreatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, &i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateComment = `-- name: UpdateComment :one
UPDATE comments
SET text = $2
WHERE id = $1
RETURNING id, user_id, sku, text, created_at
`

type UpdateCommentParams struct {
	ID   int64
	Text string
}

func (q *Queries) UpdateComment(ctx context.Context, arg *UpdateCommentParams) (*Comment, error) {
	row := q.db.QueryRow(ctx, updateComment, arg.ID, arg.Text)
	var i Comment
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.Sku,
		&i.Text,
		&i.CreatedAt,
	)
	return &i, err
}
