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

package db

import (
	"context"
)

const deleteSession = `-- name: DeleteSession :execrows
DELETE FROM user_session WHERE id = $1
`

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

const deleteSessionsByUserId = `-- name: DeleteSessionsByUserId :exec
DELETE FROM user_session WHERE user_id = $1
`

func (q *Queries) DeleteSessionsByUserId(ctx context.Context, userID int64) error {
	_, err := q.db.Exec(ctx, deleteSessionsByUserId, userID)
	return err
}

const deleteUserSessionByUserIdAndWalletId = `-- name: DeleteUserSessionByUserIdAndWalletId :exec
DELETE FROM user_session WHERE user_id = $1 AND wallet_id = $2
`

type DeleteUserSessionByUserIdAndWalletIdParams struct {
	UserID   int64 `json:"user_id"`
	WalletID int64 `json:"wallet_id"`
}

func (q *Queries) DeleteUserSessionByUserIdAndWalletId(ctx context.Context, arg DeleteUserSessionByUserIdAndWalletIdParams) error {
	_, err := q.db.Exec(ctx, deleteUserSessionByUserIdAndWalletId, arg.UserID, arg.WalletID)
	return err
}

const getUserSession = `-- name: GetUserSession :one
SELECT id, user_id, wallet_id FROM user_session WHERE key = $1
`

type GetUserSessionRow struct {
	ID       int64 `json:"id"`
	UserID   int64 `json:"user_id"`
	WalletID int64 `json:"wallet_id"`
}

func (q *Queries) GetUserSession(ctx context.Context, key string) (GetUserSessionRow, error) {
	row := q.db.QueryRow(ctx, getUserSession, key)
	var i GetUserSessionRow
	err := row.Scan(&i.ID, &i.UserID, &i.WalletID)
	return i, err
}

const getUserSessions = `-- name: GetUserSessions :many
SELECT id, user_id, wallet_id FROM user_session WHERE user_id = $1
`

type GetUserSessionsRow struct {
	ID       int64 `json:"id"`
	UserID   int64 `json:"user_id"`
	WalletID int64 `json:"wallet_id"`
}

func (q *Queries) GetUserSessions(ctx context.Context, userID int64) ([]GetUserSessionsRow, error) {
	rows, err := q.db.Query(ctx, getUserSessions, userID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []GetUserSessionsRow
	for rows.Next() {
		var i GetUserSessionsRow
		if err := rows.Scan(&i.ID, &i.UserID, &i.WalletID); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const insertUserSession = `-- name: InsertUserSession :exec
INSERT INTO user_session (key, user_id, wallet_id) VALUES ($1, $2, $3)
`

type InsertUserSessionParams struct {
	Key      string `json:"key"`
	UserID   int64  `json:"user_id"`
	WalletID int64  `json:"wallet_id"`
}

func (q *Queries) InsertUserSession(ctx context.Context, arg InsertUserSessionParams) error {
	_, err := q.db.Exec(ctx, insertUserSession, arg.Key, arg.UserID, arg.WalletID)
	return err
}

const updateUserSessionWallet = `-- name: UpdateUserSessionWallet :exec
UPDATE user_session SET wallet_id = $1 WHERE id = $2
`

type UpdateUserSessionWalletParams struct {
	WalletID int64 `json:"wallet_id"`
	ID       int64 `json:"id"`
}

func (q *Queries) UpdateUserSessionWallet(ctx context.Context, arg UpdateUserSessionWalletParams) error {
	_, err := q.db.Exec(ctx, updateUserSessionWallet, arg.WalletID, arg.ID)
	return err
}

const updateUserSessionWalletByWalletId = `-- name: UpdateUserSessionWalletByWalletId :exec
UPDATE user_session SET wallet_id = $1::bigint WHERE wallet_id = $2::bigint
`

type UpdateUserSessionWalletByWalletIdParams struct {
	NewWalletID int64 `json:"new_wallet_id"`
	OldWalletID int64 `json:"old_wallet_id"`
}

func (q *Queries) UpdateUserSessionWalletByWalletId(ctx context.Context, arg UpdateUserSessionWalletByWalletIdParams) error {
	_, err := q.db.Exec(ctx, updateUserSessionWalletByWalletId, arg.NewWalletID, arg.OldWalletID)
	return err
}
