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

package db

import (
	"context"

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

const createPasskey = `-- name: CreatePasskey :execresult
INSERT INTO passkeys (
  id, cred_id, name, created_at, user_id, credential
) VALUES (
  $1, $2, $3, $4, $5, $6
)
`

type CreatePasskeyParams struct {
	ID         string
	CredID     []byte
	Name       string
	CreatedAt  int64
	UserID     string
	Credential []byte
}

func (q *Queries) CreatePasskey(ctx context.Context, arg CreatePasskeyParams) (pgconn.CommandTag, error) {
	return q.db.Exec(ctx, createPasskey,
		arg.ID,
		arg.CredID,
		arg.Name,
		arg.CreatedAt,
		arg.UserID,
		arg.Credential,
	)
}

const deletePasskey = `-- name: DeletePasskey :execresult
DELETE FROM passkeys WHERE user_id = $1 AND id = $2
`

type DeletePasskeyParams struct {
	UserID string
	ID     string
}

func (q *Queries) DeletePasskey(ctx context.Context, arg DeletePasskeyParams) (pgconn.CommandTag, error) {
	return q.db.Exec(ctx, deletePasskey, arg.UserID, arg.ID)
}

const findPasskey = `-- name: FindPasskey :one
SELECT id, cred_id, name, created_at, user_id, credential FROM passkeys WHERE user_id = $1 AND id = $2
`

type FindPasskeyParams struct {
	UserID string
	ID     string
}

func (q *Queries) FindPasskey(ctx context.Context, arg FindPasskeyParams) (Passkey, error) {
	row := q.db.QueryRow(ctx, findPasskey, arg.UserID, arg.ID)
	var i Passkey
	err := row.Scan(
		&i.ID,
		&i.CredID,
		&i.Name,
		&i.CreatedAt,
		&i.UserID,
		&i.Credential,
	)
	return i, err
}

const findPasskeys = `-- name: FindPasskeys :many
SELECT id, cred_id, name, created_at, user_id, credential FROM passkeys WHERE user_id = $1
`

func (q *Queries) FindPasskeys(ctx context.Context, userID string) ([]Passkey, error) {
	rows, err := q.db.Query(ctx, findPasskeys, userID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Passkey
	for rows.Next() {
		var i Passkey
		if err := rows.Scan(
			&i.ID,
			&i.CredID,
			&i.Name,
			&i.CreatedAt,
			&i.UserID,
			&i.Credential,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updatePasskey = `-- name: UpdatePasskey :execresult
UPDATE passkeys SET name = $1 WHERE user_id = $2 AND id = $3
`

type UpdatePasskeyParams struct {
	Name   string
	UserID string
	ID     string
}

func (q *Queries) UpdatePasskey(ctx context.Context, arg UpdatePasskeyParams) (pgconn.CommandTag, error) {
	return q.db.Exec(ctx, updatePasskey, arg.Name, arg.UserID, arg.ID)
}

const updatePasskeyCredential = `-- name: UpdatePasskeyCredential :execresult
UPDATE passkeys SET credential = $1 WHERE user_id = $2 AND cred_id = $3
`

type UpdatePasskeyCredentialParams struct {
	Credential []byte
	UserID     string
	CredID     []byte
}

func (q *Queries) UpdatePasskeyCredential(ctx context.Context, arg UpdatePasskeyCredentialParams) (pgconn.CommandTag, error) {
	return q.db.Exec(ctx, updatePasskeyCredential, arg.Credential, arg.UserID, arg.CredID)
}
