// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.30.0
// source: queries.sql

package sqlc

import (
	"context"
	"database/sql"
)

const createEncryptedLog = `-- name: CreateEncryptedLog :one
INSERT INTO encrypted_logs (
    log_type, encrypted_payload, blind_index_hash, server_id, session_id
) VALUES (
    $1, $2, $3, $4, $5
) RETURNING id, log_type, created_at, encrypted_payload, blind_index_hash, server_id, session_id
`

type CreateEncryptedLogParams struct {
	LogType          string         `json:"log_type"`
	EncryptedPayload []byte         `json:"encrypted_payload"`
	BlindIndexHash   sql.NullString `json:"blind_index_hash"`
	ServerID         string         `json:"server_id"`
	SessionID        sql.NullString `json:"session_id"`
}

func (q *Queries) CreateEncryptedLog(ctx context.Context, arg CreateEncryptedLogParams) (EncryptedLog, error) {
	row := q.db.QueryRowContext(ctx, createEncryptedLog,
		arg.LogType,
		arg.EncryptedPayload,
		arg.BlindIndexHash,
		arg.ServerID,
		arg.SessionID,
	)
	var i EncryptedLog
	err := row.Scan(
		&i.ID,
		&i.LogType,
		&i.CreatedAt,
		&i.EncryptedPayload,
		&i.BlindIndexHash,
		&i.ServerID,
		&i.SessionID,
	)
	return i, err
}

const createTelemetry = `-- name: CreateTelemetry :one
INSERT INTO telemetry (
    community_id, server_fps, player_count
) VALUES (
    $1, $2, $3
) RETURNING timestamp, community_id, server_fps, player_count
`

type CreateTelemetryParams struct {
	CommunityID string  `json:"community_id"`
	ServerFps   float64 `json:"server_fps"`
	PlayerCount int32   `json:"player_count"`
}

func (q *Queries) CreateTelemetry(ctx context.Context, arg CreateTelemetryParams) (Telemetry, error) {
	row := q.db.QueryRowContext(ctx, createTelemetry, arg.CommunityID, arg.ServerFps, arg.PlayerCount)
	var i Telemetry
	err := row.Scan(
		&i.Timestamp,
		&i.CommunityID,
		&i.ServerFps,
		&i.PlayerCount,
	)
	return i, err
}

const getRecentLogs = `-- name: GetRecentLogs :many
SELECT id, log_type, created_at, encrypted_payload, blind_index_hash, server_id, session_id FROM encrypted_logs
WHERE server_id = $1
ORDER BY created_at DESC
LIMIT $2
`

type GetRecentLogsParams struct {
	ServerID string `json:"server_id"`
	Limit    int32  `json:"limit"`
}

func (q *Queries) GetRecentLogs(ctx context.Context, arg GetRecentLogsParams) ([]EncryptedLog, error) {
	rows, err := q.db.QueryContext(ctx, getRecentLogs, arg.ServerID, arg.Limit)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []EncryptedLog
	for rows.Next() {
		var i EncryptedLog
		if err := rows.Scan(
			&i.ID,
			&i.LogType,
			&i.CreatedAt,
			&i.EncryptedPayload,
			&i.BlindIndexHash,
			&i.ServerID,
			&i.SessionID,
		); 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
}
