
// Hooks for service `<%= serviceName %>`. (Can be re-generated.)
<%- hooks.imports.join(EOL) %>
<%# -%>
<%# --- forEach-1 starts below. -%>
<% _hooks.forEach(__hook => { -%>
// <%- lintDisableNextLineUnused %>
<%- tplImports(__hook.camelName, `${__hook.filePath}${__hook.fileName}`) %>
<% }) -%>
<%# --- forEach-1 ends above. -%>
<%# -%>
<%# --- if-2 starts below. -%>
<% if (graphqlTypeName) { -%>
// <%- lintDisableNextLineUnused %>
<%- tplImports(`${serviceName}Populate`, `./${kebabName}.populate`) %>
<% } -%>
<%# --- if-2 ends above. -%>
<%- insertFragment('imports') %>

<% __validate = isJs ? [
    `// ${lintDisableNextLineUnused}`,
    `const { ${hooks.hooks.join(', ')} } = commonHooks${sc}`,
    `// ${lintDisableNextLineUnused}`,
    `${tplImports('{ create, update, patch, validateCreate, validateUpdate, validatePatch }', `./${kebabName}.validate`)}`
] : [
    `// ${lintDisableNextLineUnused}`,
    `const { ${hooks.hooks.join(', ')} } = commonHooks${sc}`,
    tplImports('validate', `./${kebabName}.validate`),
    `// ${lintDisableNextLineUnused}`,
    `const { create, update, patch, validateCreate, validateUpdate, validatePatch } = validate${sc}`
] -%>
<%- insertFragment('used', serviceName !== 'graphql' ? __validate : [
      `// ${lintDisableNextLineUnused}`,
      `const { ${hooks.hooks.join(', ')} } = commonHooks${sc}`,
    ]
) %>
<%# -%>
<%# === Foreign keys =========================================================================== -%>
<%# -%>
<%# --- if-3 starts below. (mongodb only) -%>
<% if ((mapping.feathers[serviceName] || {}).adapter === 'mongodb') { -%>
<%- insertFragment('foreign_keys', [
  `// ${lintDisableNextLineUnused}`,
  `const foreignKeys${tplTsOnly([': string | string[]'])} = ${stringifyPlus(feathersSpecs[serviceName]._extensions.foreignKeys).replace(/"/g, '\'')}${sc}`,
]) -%>
<% } -%>
<%# --- if-3 ends above. -%>
<%# %>
<%- insertFragment('init') %>
<%# === Before ================================================================================= -%>

<%- tplModuleExports('HooksObject', '{', '{') %>
  before: {
<% if (hooks.comments.before.length) { -%>
<%- hooks.comments.before.map(str => `    ${str}`).join(EOL) %>
<% } -%>
    <%- insertFragment('before', [
      `    all: [${hooks.make(hooks.code.before.all)}],`,
      `    find: [${hooks.make(hooks.code.before.find)}],`,
      `    get: [${hooks.make(hooks.code.before.get)}],`,
      `    create: [${hooks.make(hooks.code.before.create)}],`,
      `    update: [${hooks.make(hooks.code.before.update)}],`,
      `    patch: [${hooks.make(hooks.code.before.patch)}],`,
      `    remove: [${hooks.make(hooks.code.before.remove)}]`,
    ]) %>
  },
<%# -%>
<%# === After  ================================================================================= -%>

  after: {
<% if (hooks.comments.after.length) { -%>
<%- hooks.comments.after.map(str => `    ${str}`).join(EOL) %>
<% } -%>
    <%- insertFragment('after', [
        `    all: [${hooks.make(hooks.code.after.all)}],`,
        `    find: [${hooks.make(hooks.code.after.find)}],`,
        `    get: [${hooks.make(hooks.code.after.get)}],`,
        `    create: [${hooks.make(hooks.code.after.create)}],`,
        `    update: [${hooks.make(hooks.code.after.update)}],`,
        `    patch: [${hooks.make(hooks.code.after.patch)}],`,
        `    remove: [${hooks.make(hooks.code.after.remove)}]`,
    ]) %>
  },
<%# -%>
<%# === Error ================================================================================== -%>

  error: {
<% if (hooks.comments.error.length) { -%>
<%- hooks.comments.error.map(str => `    ${str}`).join(EOL) %>
<% } -%>
    <%- insertFragment('error', [
        `    all: [${hooks.make(hooks.code.error.all)}],`,
        `    find: [${hooks.make(hooks.code.error.find)}],`,
        `    get: [${hooks.make(hooks.code.error.get)}],`,
        `    create: [${hooks.make(hooks.code.error.create)}],`,
        `    update: [${hooks.make(hooks.code.error.update)}],`,
        `    patch: [${hooks.make(hooks.code.error.patch)}],`,
        `    remove: [${hooks.make(hooks.code.error.remove)}]`,
    ]) %>
  },
  <%- insertFragment('moduleExports') %>
}<%- sc %>

<%- insertFragment('exports') %>
<%- `${tplExport('moduleExports')}${sc}` %>

<%- insertFragment('funcs') %>
<%- insertFragment('end') %>
