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

package generated

import (
	"context"

	"github.com/jackc/pgx/v5/pgtype"
)

const createRefreshToken = `-- name: CreateRefreshToken :one
INSERT INTO refresh_tokens (
    usuario_id, token_hash, user_agent, ip, expira_em
) VALUES (
    $1, $2, $3, $4, $5
) RETURNING id, usuario_id, token_hash, user_agent, ip, expira_em, revogado, criado_em
`

type CreateRefreshTokenParams struct {
	UsuarioID pgtype.UUID        `json:"usuario_id"`
	TokenHash string             `json:"token_hash"`
	UserAgent pgtype.Text        `json:"user_agent"`
	Ip        pgtype.Text        `json:"ip"`
	ExpiraEm  pgtype.Timestamptz `json:"expira_em"`
}

func (q *Queries) CreateRefreshToken(ctx context.Context, arg CreateRefreshTokenParams) (RefreshToken, error) {
	row := q.db.QueryRow(ctx, createRefreshToken,
		arg.UsuarioID,
		arg.TokenHash,
		arg.UserAgent,
		arg.Ip,
		arg.ExpiraEm,
	)
	var i RefreshToken
	err := row.Scan(
		&i.ID,
		&i.UsuarioID,
		&i.TokenHash,
		&i.UserAgent,
		&i.Ip,
		&i.ExpiraEm,
		&i.Revogado,
		&i.CriadoEm,
	)
	return i, err
}

const getRefreshToken = `-- name: GetRefreshToken :one
SELECT id, usuario_id, token_hash, user_agent, ip, expira_em, revogado, criado_em FROM refresh_tokens
WHERE token_hash = $1 LIMIT 1
`

func (q *Queries) GetRefreshToken(ctx context.Context, tokenHash string) (RefreshToken, error) {
	row := q.db.QueryRow(ctx, getRefreshToken, tokenHash)
	var i RefreshToken
	err := row.Scan(
		&i.ID,
		&i.UsuarioID,
		&i.TokenHash,
		&i.UserAgent,
		&i.Ip,
		&i.ExpiraEm,
		&i.Revogado,
		&i.CriadoEm,
	)
	return i, err
}

const revokeAllUserTokens = `-- name: RevokeAllUserTokens :exec
UPDATE refresh_tokens
SET revogado = TRUE
WHERE usuario_id = $1
`

func (q *Queries) RevokeAllUserTokens(ctx context.Context, usuarioID pgtype.UUID) error {
	_, err := q.db.Exec(ctx, revokeAllUserTokens, usuarioID)
	return err
}

const revokeRefreshToken = `-- name: RevokeRefreshToken :exec
UPDATE refresh_tokens
SET revogado = TRUE
WHERE token_hash = $1
`

func (q *Queries) RevokeRefreshToken(ctx context.Context, tokenHash string) error {
	_, err := q.db.Exec(ctx, revokeRefreshToken, tokenHash)
	return err
}
