group TagDefinitionDao: EntitySqlDao;

tableName() ::= "tag_definitions"

tableFields(prefix) ::= <<
  <prefix>name
, <prefix>description
, <prefix>is_active
, <prefix>created_by
, <prefix>created_date
, <prefix>updated_by
, <prefix>updated_date
>>

tableValues() ::= <<
  :name
, :description
, :isActive
, :createdBy
, :createdDate
, :updatedBy
, :updatedDate
>>

accountRecordIdFieldWithComma(prefix) ::= ""

accountRecordIdValueWithComma() ::= ""

historyTableName() ::= "tag_definition_history"

markTagDefinitionAsDeleted() ::= <<
update <tableName()> t
set t.is_active = 0
where <idField("t.")> = :id
<AND_CHECK_TENANT("t.")>
;
>>

tagDefinitionUsageCount() ::= <<
select
  count(<idField("t.")>)
from tags t
where t.is_active
and t.tag_definition_id = :id
<AND_CHECK_TENANT("t.")>
;
>>

getByName() ::= <<
select
  <allTableFields("t.")>
from <tableName()> t
where t.name = :name
and t.is_active
<AND_CHECK_TENANT("t.")>
;
>>

getByIds(tag_definition_ids) ::= <<
select
  <allTableFields("t.")>
from <tableName()> t
where t.is_active
and <idField("t.")> in (<tag_definition_ids: {id | :id_<i0>}; separator="," >)
<AND_CHECK_TENANT("t.")>
;
>>

get(limit) ::= <<
select
<allTableFields("t.")>
from <tableName()> t
where
t.is_active
<AND_CHECK_TENANT("t.")>
<if(limit)>limit :limit<endif>
;
>>
