// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.25.0
// source: wallet_session.sql

package db

import (
	"context"

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

const createWalletSession = `-- name: CreateWalletSession :exec
INSERT INTO wallet_session (key, wallet_id, name) VALUES ($1, $2, $3)
`

type CreateWalletSessionParams struct {
	Key      string      `json:"key"`
	WalletID int64       `json:"wallet_id"`
	Name     pgtype.Text `json:"name"`
}

func (q *Queries) CreateWalletSession(ctx context.Context, arg CreateWalletSessionParams) error {
	_, err := q.db.Exec(ctx, createWalletSession, arg.Key, arg.WalletID, arg.Name)
	return err
}

const deleteWalletSession = `-- name: DeleteWalletSession :execrows
DELETE FROM wallet_session WHERE id = $1
`

func (q *Queries) DeleteWalletSession(ctx context.Context, id int64) (int64, error) {
	result, err := q.db.Exec(ctx, deleteWalletSession, id)
	if err != nil {
		return 0, err
	}
	return result.RowsAffected(), nil
}

const deleteWalletSessionsByWalletId = `-- name: DeleteWalletSessionsByWalletId :exec
DELETE FROM wallet_session WHERE wallet_id = $1
`

func (q *Queries) DeleteWalletSessionsByWalletId(ctx context.Context, walletID int64) error {
	_, err := q.db.Exec(ctx, deleteWalletSessionsByWalletId, walletID)
	return err
}

const getWalletSession = `-- name: GetWalletSession :one
SELECT wallet_id FROM wallet_session WHERE key = $1
`

func (q *Queries) GetWalletSession(ctx context.Context, key string) (int64, error) {
	row := q.db.QueryRow(ctx, getWalletSession, key)
	var wallet_id int64
	err := row.Scan(&wallet_id)
	return wallet_id, err
}

const getWalletSessionsByWalletId = `-- name: GetWalletSessionsByWalletId :many
SELECT id, wallet_id, name, key FROM wallet_session WHERE wallet_id = $1
`

func (q *Queries) GetWalletSessionsByWalletId(ctx context.Context, walletID int64) ([]WalletSession, error) {
	rows, err := q.db.Query(ctx, getWalletSessionsByWalletId, walletID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []WalletSession
	for rows.Next() {
		var i WalletSession
		if err := rows.Scan(
			&i.ID,
			&i.WalletID,
			&i.Name,
			&i.Key,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}
