group TagDefinitionDao;

CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"

fields(prefix) ::= <<
    <prefix>id,
    <prefix>name,
    <prefix>description,
    <prefix>created_by,
    <prefix>created_date ,
    <prefix>updated_by,
    <prefix>updated_date,
    <prefix>tenant_record_id
>>

get() ::= <<
  SELECT <fields()>
  FROM tag_definitions
  WHERE <CHECK_TENANT()>
  ;
>>

create() ::= <<
  INSERT INTO tag_definitions(<fields()>)
  VALUES(:id, :name, :description, :userName, :createdDate, :userName, :updatedDate, :tenantRecordId);
>>

load() ::= <<
  SELECT <fields()>
  FROM tag_definitions
  WHERE id = :id
  <AND_CHECK_TENANT()>
  ;
>>


deleteTagDefinition() ::= <<
  DELETE FROM tag_definitions
  WHERE id = :id
  <AND_CHECK_TENANT()>
  ;
>>

tagDefinitionUsageCount() ::= <<
  SELECT COUNT(id)
  FROM tags
  WHERE tag_definition_id = :id
  <AND_CHECK_TENANT()>
>>

getByName() ::= <<
  SELECT <fields()>
   FROM tag_definitions
  WHERE name = :name
  <AND_CHECK_TENANT()>
  ;
>>

getById() ::= <<
  SELECT <fields()>
  FROM tag_definitions
  WHERE id = :id
  <AND_CHECK_TENANT()>
  ;
>>

getByIds(tag_definition_ids) ::= <<
  SELECT <fields()>
  FROM tag_definitions
  WHERE id IN (<tag_definition_ids: {id | :id_<i0>}; separator="," >)
  <AND_CHECK_TENANT()>
>>
;
