// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: transfer.sql

package dbgen

import (
	"context"

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

const CreateTransfer = `-- name: CreateTransfer :one
INSERT INTO wallet_transfer (
        amount,
        type,
        receiver_wallet_id,
        sender_wallet_id,
        cashier_id,
        verified,
        reference_number,
        status,
        payment_method
    )
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
RETURNING id, amount, type, receiver_wallet_id, sender_wallet_id, cashier_id, verified, reference_number, status, payment_method, created_at, updated_at
`

type CreateTransferParams struct {
	Amount           pgtype.Int8 `json:"amount"`
	Type             pgtype.Text `json:"type"`
	ReceiverWalletID pgtype.Int8 `json:"receiver_wallet_id"`
	SenderWalletID   pgtype.Int8 `json:"sender_wallet_id"`
	CashierID        pgtype.Int8 `json:"cashier_id"`
	Verified         pgtype.Bool `json:"verified"`
	ReferenceNumber  pgtype.Text `json:"reference_number"`
	Status           pgtype.Text `json:"status"`
	PaymentMethod    pgtype.Text `json:"payment_method"`
}

func (q *Queries) CreateTransfer(ctx context.Context, arg CreateTransferParams) (WalletTransfer, error) {
	row := q.db.QueryRow(ctx, CreateTransfer,
		arg.Amount,
		arg.Type,
		arg.ReceiverWalletID,
		arg.SenderWalletID,
		arg.CashierID,
		arg.Verified,
		arg.ReferenceNumber,
		arg.Status,
		arg.PaymentMethod,
	)
	var i WalletTransfer
	err := row.Scan(
		&i.ID,
		&i.Amount,
		&i.Type,
		&i.ReceiverWalletID,
		&i.SenderWalletID,
		&i.CashierID,
		&i.Verified,
		&i.ReferenceNumber,
		&i.Status,
		&i.PaymentMethod,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const GetAllTransfers = `-- name: GetAllTransfers :many
SELECT id, amount, type, receiver_wallet_id, sender_wallet_id, cashier_id, verified, reference_number, status, payment_method, created_at, updated_at
FROM wallet_transfer
`

func (q *Queries) GetAllTransfers(ctx context.Context) ([]WalletTransfer, error) {
	rows, err := q.db.Query(ctx, GetAllTransfers)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []WalletTransfer
	for rows.Next() {
		var i WalletTransfer
		if err := rows.Scan(
			&i.ID,
			&i.Amount,
			&i.Type,
			&i.ReceiverWalletID,
			&i.SenderWalletID,
			&i.CashierID,
			&i.Verified,
			&i.ReferenceNumber,
			&i.Status,
			&i.PaymentMethod,
			&i.CreatedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const GetTransferByID = `-- name: GetTransferByID :one
SELECT id, amount, type, receiver_wallet_id, sender_wallet_id, cashier_id, verified, reference_number, status, payment_method, created_at, updated_at
FROM wallet_transfer
WHERE id = $1
`

func (q *Queries) GetTransferByID(ctx context.Context, id int64) (WalletTransfer, error) {
	row := q.db.QueryRow(ctx, GetTransferByID, id)
	var i WalletTransfer
	err := row.Scan(
		&i.ID,
		&i.Amount,
		&i.Type,
		&i.ReceiverWalletID,
		&i.SenderWalletID,
		&i.CashierID,
		&i.Verified,
		&i.ReferenceNumber,
		&i.Status,
		&i.PaymentMethod,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const GetTransferByReference = `-- name: GetTransferByReference :one
SELECT id, amount, type, receiver_wallet_id, sender_wallet_id, cashier_id, verified, reference_number, status, payment_method, created_at, updated_at
FROM wallet_transfer
WHERE reference_number = $1
`

func (q *Queries) GetTransferByReference(ctx context.Context, referenceNumber pgtype.Text) (WalletTransfer, error) {
	row := q.db.QueryRow(ctx, GetTransferByReference, referenceNumber)
	var i WalletTransfer
	err := row.Scan(
		&i.ID,
		&i.Amount,
		&i.Type,
		&i.ReceiverWalletID,
		&i.SenderWalletID,
		&i.CashierID,
		&i.Verified,
		&i.ReferenceNumber,
		&i.Status,
		&i.PaymentMethod,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const GetTransfersByWallet = `-- name: GetTransfersByWallet :many
SELECT id, amount, type, receiver_wallet_id, sender_wallet_id, cashier_id, verified, reference_number, status, payment_method, created_at, updated_at
FROM wallet_transfer
WHERE receiver_wallet_id = $1
    OR sender_wallet_id = $1
`

func (q *Queries) GetTransfersByWallet(ctx context.Context, receiverWalletID pgtype.Int8) ([]WalletTransfer, error) {
	rows, err := q.db.Query(ctx, GetTransfersByWallet, receiverWalletID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []WalletTransfer
	for rows.Next() {
		var i WalletTransfer
		if err := rows.Scan(
			&i.ID,
			&i.Amount,
			&i.Type,
			&i.ReceiverWalletID,
			&i.SenderWalletID,
			&i.CashierID,
			&i.Verified,
			&i.ReferenceNumber,
			&i.Status,
			&i.PaymentMethod,
			&i.CreatedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const UpdateTransferStatus = `-- name: UpdateTransferStatus :exec
UPDATE wallet_transfer
SET status = $1,
    updated_at = CURRENT_TIMESTAMP
WHERE id = $2
`

type UpdateTransferStatusParams struct {
	Status pgtype.Text `json:"status"`
	ID     int64       `json:"id"`
}

func (q *Queries) UpdateTransferStatus(ctx context.Context, arg UpdateTransferStatusParams) error {
	_, err := q.db.Exec(ctx, UpdateTransferStatus, arg.Status, arg.ID)
	return err
}

const UpdateTransferVerification = `-- name: UpdateTransferVerification :exec
UPDATE wallet_transfer
SET verified = $1,
    updated_at = CURRENT_TIMESTAMP
WHERE id = $2
`

type UpdateTransferVerificationParams struct {
	Verified pgtype.Bool `json:"verified"`
	ID       int64       `json:"id"`
}

func (q *Queries) UpdateTransferVerification(ctx context.Context, arg UpdateTransferVerificationParams) error {
	_, err := q.db.Exec(ctx, UpdateTransferVerification, arg.Verified, arg.ID)
	return err
}
