/**
 * Generate slug property for {{SUB_MODULE_ENTITY_CAMELCASED_SINGULAR}}
 */
async _generateSlug(title: string, slug?: string | null): Promise<string> {
  const scenario = this.initScenario(this.logger, this._generateSlug, {
    title,
    slug,
  });
  try {
    if (!title) return slug;
    let value = slug || slugify(title);
    let retries = 0;
    let exists = true;
    while (exists) {
      const res = await this.{{SUB_MODULE_DOT_ENTITY_CAMELCASED_SINGULAR}}Model.exists({ slug: value });
      exists = !!res;
      if (exists) {
        retries++;
        value = slugify(title) + "-" + retries;
      }
    }
    scenario.set({
      slug: value,
      retries,
    });
    scenario.end();
    return value;
  } catch (error) {
    scenario.error(error);
    throw error;
  }
}