-- name: CreateShopTransaction :one
INSERT INTO shop_transactions (
        amount,
        branch_id,
        cashier_id,
        bet_id,
        type,
        payment_option,
        full_name,
        phone_number,
        bank_code,
        beneficiary_name,
        account_name,
        account_number,
        reference_number,
        number_of_outcomes,
        branch_name,
        branch_location,
        company_id,
        cashier_name
    )
VALUES (
        $1,
        $2,
        $3,
        $4,
        $5,
        $6,
        $7,
        $8,
        $9,
        $10,
        $11,
        $12,
        $13,
        $14,
        $15,
        $16,
        $17,
        $18
    )
RETURNING *;
-- name: GetAllShopTransactions :many
SELECT *
FROM shop_transactions
wHERE (
        branch_id = sqlc.narg('branch_id')
        OR sqlc.narg('branch_id') IS NULL
    )
    AND (
        company_id = sqlc.narg('company_id')
        OR sqlc.narg('company_id') IS NULL
    )
    AND (
        cashier_id = sqlc.narg('cashier_id')
        OR sqlc.narg('cashier_id') IS NULL
    )
    AND (
        full_name ILIKE '%' || sqlc.narg('query') || '%'
        OR phone_number ILIKE '%' || sqlc.narg('query') || '%'
        OR sqlc.narg('query') IS NULL
    )
    AND (
        created_at > sqlc.narg('created_before')
        OR sqlc.narg('created_before') IS NULL
    )
    AND (
        created_at < sqlc.narg('created_after')
        OR sqlc.narg('created_after') IS NULL
    );
-- name: GetShopTransactionByID :one
SELECT *
FROM shop_transactions
WHERE id = $1;
-- name: GetShopTransactionByBranch :many
SELECT *
FROM shop_transactions
WHERE branch_id = $1;
-- name: UpdateShopTransactionVerified :exec
UPDATE shop_transactions
SET verified = $2,
    approved_by = $3,
    approver_name = $4,
    updated_at = CURRENT_TIMESTAMP
WHERE id = $1;