group PaymentMethodSqlDao: EntitySqlDao;



tableName() ::= "payment_methods"

historyTableName() ::= "payment_method_history"

andCheckSoftDeletionWithComma(prefix) ::= "and <prefix>is_active"

tableFields(prefix) ::= <<
  <prefix>external_key
, <prefix>account_id
, <prefix>plugin_name
, <prefix>is_active
, <prefix>created_by
, <prefix>created_date
, <prefix>updated_by
, <prefix>updated_date
>>

tableValues() ::= <<
  :externalKey
, :accountId
, :pluginName
, :isActive
, :createdBy
, :createdDate
, :updatedBy
, :updatedDate
>>

markPaymentMethodAsDeleted(id) ::= <<
update <tableName()>
set is_active = 0
, updated_by = :updatedBy
, updated_date = :createdDate
where  id = :id
<AND_CHECK_TENANT()>
;
>>

unmarkPaymentMethodAsDeleted(id) ::= <<
update <tableName()>
set is_active = 1
, updated_by = :updatedBy
, updated_date = :createdDate
where  id = :id
<AND_CHECK_TENANT()>
;
>>

getByExternalKey() ::= <<
select <allTableFields()>
from <tableName()>
where external_key = :externalKey
and is_active = 1
<AND_CHECK_TENANT()>
;
>>

getPaymentMethodByExternalKeyIncludedDeleted() ::= <<
select <allTableFields()>
from <tableName()>
where external_key = :externalKey
<AND_CHECK_TENANT()>
;
>>

getPaymentMethodIncludedDelete(accountId) ::= <<
select <allTableFields()>
from <tableName()>
where id = :id
;
>>

getByAccountId(accountId) ::= <<
select
<allTableFields()>
from <tableName()>
where account_id = :accountId
and is_active = 1
;
>>

getByAccountIdIncludedDelete(accountId) ::= <<
select
<allTableFields()>
from <tableName()>
where account_id = :accountId
;
>>

searchQuery(prefix) ::= <<
     <idField(prefix)> = :searchKey
  or <prefix>external_key like :likeSearchKey
  or <prefix>account_id = :searchKey
  or <prefix>plugin_name like :likeSearchKey
>>

getByPluginName() ::= <<
select
<allTableFields("t.")>
from <tableName()> t
where t.plugin_name = :pluginName
and t.is_active = 1
order by t.record_id
limit :offset, :rowCount
;
>>

getCountByPluginName() ::= <<
select
  count(1) as count
from <tableName()> t
where t.plugin_name = :pluginName
and t.is_active = 1
;
>>
