group OverrideStateSqlDao;

getOverdueStateFor() ::= <<
    select
        id
      , state
      , type
      , created_date   
    from overdue_states
    where id = :id 
    order by created_date desc
    limit 1
    ;
>>

getOverdueStateForIdAndType() ::= <<
    select
        id
      , state
      , type
      , created_date   
    from overdue_states
    where id = :id 
    and type = :type
    order by created_date desc
    limit 1
    ;
>>


getOverdueHistoryFor() ::= <<
    select
        id
      , state
      , type
      , created_date   
    from overdue_states
    where id = :id 
    order by created_date asc
    ;
>>

getOverdueHistoryForIdAndType() ::= <<
    select
        id
      , state
      , type
      , created_date   
    from overdue_states
    where id = :id 
    and type = :type
    order by created_date asc
    ;
>>

setOverdueState() ::= <<
    insert into overdue_states (
        id
      , state
      , type
      , created_date
    ) values (
        :id
      , :state
      , :type
      , :created_date 
    );
>>