-- name: CreateDirectDeposit :one
INSERT INTO direct_deposits (
    customer_id, wallet_id, bank_name, account_number,
    account_holder, amount, reference_number,
    transfer_screenshot, status
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,'PENDING')
RETURNING *;

-- name: GetDirectDepositByID :one
SELECT *
FROM direct_deposits
WHERE id = $1;

-- name: DeleteDirectDeposit :exec
DELETE FROM direct_deposits
WHERE id = $1;

-- name: GetDirectDepositsByStatus :many
SELECT 
    id,
    customer_id,
    wallet_id,
    bank_name,
    account_number,
    account_holder,
    amount,
    reference_number,
    transfer_screenshot,
    status,
    created_at,
    approved_by,
    approved_at,
    rejection_reason
FROM direct_deposits
WHERE status = $1
ORDER BY created_at DESC
LIMIT $2 OFFSET $3;

-- name: CountDirectDepositsByStatus :one
SELECT COUNT(*)
FROM direct_deposits
WHERE status = $1;

-- name: ApproveDirectDeposit :exec
UPDATE direct_deposits
SET 
    status = 'APPROVED',
    approved_by = $2,
    approved_at = NOW()
WHERE 
    id = $1
    AND status = 'PENDING';

-- name: RejectDirectDeposit :exec
UPDATE direct_deposits
SET 
    status = 'REJECTED',
    approved_by = $2,       -- still track the admin who took final action
    approved_at = NOW(),
    rejection_reason = $3
WHERE 
    id = $1
    AND status = 'PENDING';

