{{! ESM }}
{{#hasEsmStyle}}
import cds from '@sap/cds'
{{#hasTyper}}
{{#allNames}}
import { {{allNames}} } from '#cds-models/{{{servicePath}}}'
{{/allNames}}
{{/hasTyper}}

{{! class declaration }}
export class {{serviceClass}} extends cds.ApplicationService { init() {
{{/hasEsmStyle}}
{{! CJS }}
{{^hasEsmStyle}}
const cds = require('@sap/cds')
{{#hasTyper}}
{{#allNames}}
const { {{allNames}} } = require('#cds-models/{{{servicePath}}}')
{{/allNames}}
{{/hasTyper}}

{{! class declaration }}
module.exports = class {{serviceClass}} extends cds.ApplicationService { init() {
{{/hasEsmStyle}}
{{! dynamic model imports }}
{{^hasTyper}}

{{#entityNames}}
  const { {{entityNames}} } = cds.entities('{{serviceName}}')
{{/entityNames}}
{{/hasTyper}}

{{! entity handlers }}
{{#entities}}
  this.before (['CREATE', 'UPDATE'], {{name}}, async (req) => {
    console.log('Before CREATE/UPDATE {{name}}', req.data)
  })
  this.after ('READ', {{name}}, async ({{dataVar}}, req) => {
    console.log('After READ {{name}}', {{dataVar}})
  })
{{/entities}}

{{! action handlers }}
{{#operations}}
{{#hasTyper}}
  this.on ({{name}}, async (req) => {
{{/hasTyper}}
{{^hasTyper}}
  this.on ('{{name}}', async (req) => {
{{/hasTyper}}
    console.log('On {{name}}', req.data)
  })
{{/operations}}

  return super.init()
}}
