group PaymentAttemptSqlDao: EntitySqlDao;

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

tableValues() ::= <<
  :paymentId
, :paymentMethodId
, :gatewayErrorCode
, :gatewayErrorMsg
, :processingStatus
, :requestedAmount
, :requestedCurrency
, :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.")>
<defaultOrderBy("pa.")>
;
>>


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