// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.26.0
// source: token.sql

package db

import (
	"context"
	"database/sql"
)

const createToken = `-- name: CreateToken :one
REPLACE INTO tokens (
  created_at, category, token_key, value_hash, expires
) VALUES (
  ?, ?, ?, ?, ?
) RETURNING created_at, category, token_key, value_hash, expires
`

type CreateTokenParams struct {
	CreatedAt int64
	Category  string
	TokenKey  string
	ValueHash []byte
	Expires   int64
}

func (q *Queries) CreateToken(ctx context.Context, arg CreateTokenParams) (Token, error) {
	row := q.db.QueryRowContext(ctx, createToken,
		arg.CreatedAt,
		arg.Category,
		arg.TokenKey,
		arg.ValueHash,
		arg.Expires,
	)
	var i Token
	err := row.Scan(
		&i.CreatedAt,
		&i.Category,
		&i.TokenKey,
		&i.ValueHash,
		&i.Expires,
	)
	return i, err
}

const deleteToken = `-- name: DeleteToken :execresult
DELETE FROM tokens WHERE (category = ? AND token_key = ?) OR expires < ?3
`

type DeleteTokenParams struct {
	Category string
	TokenKey string
	Now      int64
}

func (q *Queries) DeleteToken(ctx context.Context, arg DeleteTokenParams) (sql.Result, error) {
	return q.db.ExecContext(ctx, deleteToken, arg.Category, arg.TokenKey, arg.Now)
}

const findToken = `-- name: FindToken :one
SELECT created_at, category, token_key, value_hash, expires FROM tokens WHERE category = ? AND token_key = ? AND expires > ?3
`

type FindTokenParams struct {
	Category string
	TokenKey string
	Now      int64
}

func (q *Queries) FindToken(ctx context.Context, arg FindTokenParams) (Token, error) {
	row := q.db.QueryRowContext(ctx, findToken, arg.Category, arg.TokenKey, arg.Now)
	var i Token
	err := row.Scan(
		&i.CreatedAt,
		&i.Category,
		&i.TokenKey,
		&i.ValueHash,
		&i.Expires,
	)
	return i, err
}

const findTokenByValue = `-- name: FindTokenByValue :one
SELECT created_at, category, token_key, value_hash, expires FROM tokens WHERE category = ? AND value_hash = ? AND expires > ?3
`

type FindTokenByValueParams struct {
	Category  string
	ValueHash []byte
	Now       int64
}

func (q *Queries) FindTokenByValue(ctx context.Context, arg FindTokenByValueParams) (Token, error) {
	row := q.db.QueryRowContext(ctx, findTokenByValue, arg.Category, arg.ValueHash, arg.Now)
	var i Token
	err := row.Scan(
		&i.CreatedAt,
		&i.Category,
		&i.TokenKey,
		&i.ValueHash,
		&i.Expires,
	)
	return i, err
}
