# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

fields account_name,subaccount_name,subaccount_address,hash,type,status_,block,time,volume,fee,sender,alias,receiver,direction,delegate

date-format %Y-%m-%d %H:%M:%S
date %time

description %time +0000

# TODO: non-static symbol for asset support
account1 assets:%account_name:%subaccount_name:tezos:XTZ
amount %volume XTZ

comment type:%type, blockid:%block, subaccount_address:%subaccount_address, sender:%sender, receiver:%receiver, txid:%hash, direction:%direction

if %direction ^OUT$
  amount -%volume XTZ

# Default transfers as equity accounts
if %direction ^IN$
  account2 equity:%account_name:%subaccount_name:tezos:withdrawal:XTZ

if %direction ^OUT$
  account2 equity:%account_name:%subaccount_name:tezos:deposit:XTZ

# ---------------------------------------------------------------------------- #
#                                   Statuses                                   #
# ---------------------------------------------------------------------------- #

# TODO: support all statuses
if %status_ ^backtracked$
  skip

# ---------------------------------------------------------------------------- #
#                                     Fees                                     #
# ---------------------------------------------------------------------------- #

if %direction ^OUT$
& %fee [1-9]
  account3 assets:%account_name:%subaccount_name:tezos:XTZ
  amount3 -%fee XTZ
  account4 expenses:%account_name:%subaccount_name:tezos:fees:XTZ
  amount4 %fee XTZ
  comment type:%type, blockid:%block, subaccount_address:%subaccount_address, sender:%sender, receiver:%receiver, txid:%hash, direction:%direction, taxed_as:SPEND
  comment3 %time +0000,SPEND,%account_name:%subaccount_name:tezos,XTZ,%fee,USD,,FEE
# NOTE: in custom rules, use comment2 for SPENDs outside of fee

# ---------------------------------------------------------------------------- #
#                                  Contracts                                   #
# ---------------------------------------------------------------------------- #

# NOTE: 
#   - delegation doesn't account for "moving" from delegate to another delegate
#   - if delegate is null, it's because of 'undelegated'
#   - fees must be caught above (in this file)
if %direction ^OUT$
& %type ^delegation$
  account1 assets:%account_name:%subaccount_name:tezos:XTZ
  account2 assets:%account_name:%subaccount_name:tezos:XTZ
  comment type:%type, blockid:%block, subaccount_address:%subaccount_address, sender:%sender, txid:%hash, direction:%direction, taxed_as:SPEND

# 0 value tx (plus fees)
if %direction ^OUT$
& %type (^reveal$|^origination$)
  account1
  account2
  comment type:%type, blockid:%block, subaccount_address:%subaccount_address, sender:%sender, txid:%hash, direction:%direction, taxed_as:SPEND

# ---------------------------------------------------------------------------- #
#                                    Staking                                   #
# ---------------------------------------------------------------------------- #

include ./rules.d/baker.rules

# vim: sw=2 sts=2 si ai et
