group BusinessInvoicePayment;

CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"

getInvoicePayment(payment_id) ::= <<
select
  payment_id
, created_date
, updated_date
, ext_first_payment_ref_id
, ext_second_payment_ref_id
, account_key
, invoice_id
, effective_date
, amount
, currency
, payment_error
, processing_status
, requested_amount
, plugin_name
, payment_type
, payment_method
, card_type
, card_country
, invoice_payment_type
, linked_invoice_payment_id
, tenant_record_id
from bip
where payment_id = :payment_id
<AND_CHECK_TENANT()>
limit 1
;
>>

getInvoicePaymentsForAccountByKey(account_key) ::= <<
select
  payment_id
, created_date
, updated_date
, ext_first_payment_ref_id
, ext_second_payment_ref_id
, account_key
, invoice_id
, effective_date
, amount
, currency
, payment_error
, processing_status
, requested_amount
, plugin_name
, payment_type
, payment_method
, card_type
, card_country
, invoice_payment_type
, linked_invoice_payment_id
, tenant_record_id
from bip
where account_key = :account_key
<AND_CHECK_TENANT()>
order by created_date asc
;
>>

createInvoicePayment() ::= <<
insert into bip (
  payment_id
, created_date
, updated_date
, ext_first_payment_ref_id
, ext_second_payment_ref_id
, account_key
, invoice_id
, effective_date
, amount
, currency
, payment_error
, processing_status
, requested_amount
, plugin_name
, payment_type
, payment_method
, card_type
, card_country
, invoice_payment_type
, linked_invoice_payment_id
, account_record_id
, tenant_record_id
) values (
  :payment_id
, :created_date
, :updated_date
, :ext_first_payment_ref_id
, :ext_second_payment_ref_id
, :account_key
, :invoice_id
, :effective_date
, :amount
, :currency
, :payment_error
, :processing_status
, :requested_amount
, :plugin_name
, :payment_type
, :payment_method
, :card_type
, :card_country
, :invoice_payment_type
, :linked_invoice_payment_id
, :accountRecordId
, :tenantRecordId
);
>>

deleteInvoicePayment(payment_id) ::= <<
delete from bip where payment_id = :payment_id <AND_CHECK_TENANT()>
>>

test() ::= <<
select 1 from bip where <CHECK_TENANT()> limit 1;
>>
