group BundleSqlDao;

fields(prefix) ::= <<
    <prefix>id,
    <prefix>start_date,
    <prefix>external_key,
    <prefix>account_id,
    <prefix>last_sys_update_date
>>

insertBundle() ::= <<
    insert into bundles (<fields()>)
    values (:id, :startDate, :externalKey, :accountId, :lastSysUpdateDate);
>>

updateBundleLastSysTime()  ::= <<
    update bundles
    set
        last_sys_update_date = :lastSysUpdateDate
    where id = :id
    ;
>>

getBundleFromId() ::= <<
    select <fields()>
    from bundles
    where
      id = :id
    ;
>>

getBundleFromKey() ::= <<
    select <fields()>
    from bundles
    where
      external_key = :externalKey
    ;
>>

getBundleFromAccount() ::= <<
    select <fields()>
    from bundles
    where
      account_id = :accountId
    ;
>>

getRecordId() ::= <<
    SELECT record_id
    FROM bundles
    WHERE id = :id;
>>

auditFields(prefix) ::= <<
    <prefix>table_name,
    <prefix>record_id,
    <prefix>change_type,
    <prefix>change_date,
    <prefix>changed_by,
    <prefix>reason_code,
    <prefix>comments,
    <prefix>user_token
>>

insertAuditFromTransaction() ::= <<
    INSERT INTO audit_log(<auditFields()>)
    VALUES(:tableName, :recordId, :changeType, :createdDate, :userName, :reasonCode, :comment, :userToken);
>>