group PaymentAttemptSqlDao: EntitySqlDao;

tableFields(prefix) ::= <<
  <prefix>payment_id
, <prefix>gateway_error_code
, <prefix>gateway_error_msg
, <prefix>processing_status
, <prefix>requested_amount
, <prefix>created_by
, <prefix>created_date
, <prefix>updated_by
, <prefix>updated_date
>>

tableValues() ::= <<
  :paymentId
, :gatewayErrorCode
, :gatewayErrorMsg
, :processingStatus
, :requestedAmount
, :createdBy
, :createdDate
, :updatedBy
, :updatedDate
>>

tableName() ::= "payment_attempts"

historyTableName() ::= "payment_attempt_history"


getById(id) ::= <<
select <allTableFields("pa.")>
, pa.created_date as effective_date
, p.account_id as account_id
, p.invoice_id as invoice_id
from <tableName()> pa join payments p
where pa.id = :id
and pa.payment_id = p.id
<AND_CHECK_TENANT("pa.")>
<AND_CHECK_TENANT("p.")>
;
>>

getByPaymentId(paymentId) ::= <<
select <allTableFields("pa.")>
, pa.created_date as effective_date
, p.account_id as account_id
, p.invoice_id as invoice_id
from <tableName()> pa join payments p
where pa.payment_id = :paymentId
and p.id = :paymentId
<AND_CHECK_TENANT("pa.")>
<AND_CHECK_TENANT("p.")>
order by effective_date asc
;
>>


updatePaymentAttemptStatus() ::= <<
update <tableName()>
set processing_status = :processingStatus
, gateway_error_code = :gatewayErrorCode
, gateway_error_msg = :gatewayErrorMsg
where id = :id
<AND_CHECK_TENANT()>
;
>>
