-- name: GetTransaction :one
SELECT * FROM display_transactions
WHERE id = $1;

-- name: CreateTransaction :one
INSERT INTO transactions
(date, memo, amount, account_id, payee_id, category_id, group_id, status)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING *;

-- name: UpdateTransaction :exec
UPDATE transactions
SET date = $1,
    memo = $2,
    amount = $3,
    payee_id = $4,
    category_id = $5
WHERE id = $6;

-- name: SetTransactionReconciled :exec
UPDATE transactions
SET status = 'Reconciled'
WHERE id = $1;

-- name: DeleteTransaction :exec
DELETE FROM transactions
WHERE id = $1;

-- name: GetAllTransactionsForBudget :many
SELECT  t.*
FROM display_transactions AS t
WHERE t.budget_id = $1;

-- name: GetTransactionsForAccount :many
SELECT  t.*
FROM display_transactions AS t
WHERE t.account_id = $1
LIMIT 200;

-- name: DeleteAllTransactions :execrows
DELETE FROM transactions
USING accounts
WHERE accounts.budget_id = @budget_id
AND accounts.id = transactions.account_id;

-- name: GetTransactionsByMonthAndCategory :many
SELECT *
FROM transactions_by_month
WHERE transactions_by_month.budget_id = @budget_id;