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

package db

import (
	"context"
	"database/sql"
)

const createLog = `-- name: CreateLog :exec
INSERT INTO logs (
    id,
    session_id,
    timestamp,
    level,
    message,
    attributes,
    created_at
) VALUES (
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?
)
`

type CreateLogParams struct {
	ID         string         `json:"id"`
	SessionID  sql.NullString `json:"session_id"`
	Timestamp  int64          `json:"timestamp"`
	Level      string         `json:"level"`
	Message    string         `json:"message"`
	Attributes sql.NullString `json:"attributes"`
	CreatedAt  int64          `json:"created_at"`
}

func (q *Queries) CreateLog(ctx context.Context, arg CreateLogParams) error {
	_, err := q.exec(ctx, q.createLogStmt, createLog,
		arg.ID,
		arg.SessionID,
		arg.Timestamp,
		arg.Level,
		arg.Message,
		arg.Attributes,
		arg.CreatedAt,
	)
	return err
}

const listAllLogs = `-- name: ListAllLogs :many
SELECT id, session_id, timestamp, level, message, attributes, created_at FROM logs
ORDER BY timestamp DESC
LIMIT ?
`

func (q *Queries) ListAllLogs(ctx context.Context, limit int64) ([]Log, error) {
	rows, err := q.query(ctx, q.listAllLogsStmt, listAllLogs, limit)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Log{}
	for rows.Next() {
		var i Log
		if err := rows.Scan(
			&i.ID,
			&i.SessionID,
			&i.Timestamp,
			&i.Level,
			&i.Message,
			&i.Attributes,
			&i.CreatedAt,
		); 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 listLogsBySession = `-- name: ListLogsBySession :many
SELECT id, session_id, timestamp, level, message, attributes, created_at FROM logs
WHERE session_id = ?
ORDER BY timestamp ASC
`

func (q *Queries) ListLogsBySession(ctx context.Context, sessionID sql.NullString) ([]Log, error) {
	rows, err := q.query(ctx, q.listLogsBySessionStmt, listLogsBySession, sessionID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Log{}
	for rows.Next() {
		var i Log
		if err := rows.Scan(
			&i.ID,
			&i.SessionID,
			&i.Timestamp,
			&i.Level,
			&i.Message,
			&i.Attributes,
			&i.CreatedAt,
		); 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
}
