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

package dbgen

import (
	"context"
)

const cleanupExpiredLockouts = `-- name: CleanupExpiredLockouts :exec
DELETE FROM rate_lockouts WHERE expires_at <= ?
`

func (q *Queries) CleanupExpiredLockouts(ctx context.Context, expiresAt string) error {
	_, err := q.db.ExecContext(ctx, cleanupExpiredLockouts, expiresAt)
	return err
}

const deleteLockout = `-- name: DeleteLockout :exec
DELETE FROM rate_lockouts WHERE key = ?
`

func (q *Queries) DeleteLockout(ctx context.Context, key string) error {
	_, err := q.db.ExecContext(ctx, deleteLockout, key)
	return err
}

const loadActiveLockouts = `-- name: LoadActiveLockouts :many
SELECT key, expires_at FROM rate_lockouts WHERE expires_at > ?
`

func (q *Queries) LoadActiveLockouts(ctx context.Context, expiresAt string) ([]RateLockout, error) {
	rows, err := q.db.QueryContext(ctx, loadActiveLockouts, expiresAt)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []RateLockout{}
	for rows.Next() {
		var i RateLockout
		if err := rows.Scan(&i.Key, &i.ExpiresAt); 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 upsertLockout = `-- name: UpsertLockout :exec
INSERT OR REPLACE INTO rate_lockouts (key, expires_at) VALUES (?, ?)
`

type UpsertLockoutParams struct {
	Key       string `json:"key"`
	ExpiresAt string `json:"expiresAt"`
}

func (q *Queries) UpsertLockout(ctx context.Context, arg UpsertLockoutParams) error {
	_, err := q.db.ExecContext(ctx, upsertLockout, arg.Key, arg.ExpiresAt)
	return err
}
