group BlockingStateSqlDao: EntitySqlDao;


tableName() ::= "blocking_states"

tableFields(prefix) ::= <<
  <prefix>blockable_id
, <prefix>type
, <prefix>state
, <prefix>service
, <prefix>block_change
, <prefix>block_entitlement
, <prefix>block_billing
, <prefix>created_date
>>


tableValues() ::= <<
  :blockableId
, :type
, :state
, :service
, :blockChange
, :blockEntitlement
, :blockBilling
, :createdDate
>>

getBlockingStateFor() ::= <<
select
<allTableFields()>
from
<tableName()>
where blockable_id = :blockableId
<AND_CHECK_TENANT()>
-- We want the current state, hence the order desc and limit 1
order by record_id desc
limit 1
;
>>

getBlockingHistoryFor() ::= <<
select
<allTableFields()>
from
<tableName()>
where blockable_id = :blockableId
<AND_CHECK_TENANT()>
-- We want the current state, hence the order desc and limit 1
order by record_id asc
;
>>
