
// Class for the custom service `<%= serviceName %>` on path `/<%= path %>`. (Can be re-generated.)
/* <%- lintDisableUnused %> */
<%# -%>
<%# --- if-1 starts below. JAVASCRIPT ---------------------------------------------------------- -%>
<% if (isJs) { %>
<%- insertFragment('imports') %>
<%- insertFragment('init') %>

class Service {
  constructor (options) {
    this.options = options || {}<%- sc %>
    <%- insertFragment('constructor1') %>
  }

  <%- insertFragment('find', [
    '  async find (params) {',
    `    return []${sc}`,
    '  }',
  ]) %>

  <%- insertFragment('get', [
    '  async get (id, params) {',
    '    return {',
    '      id, text: `A new message with ID: ${id}!`',
    `    }${sc}`,
    '  }',
  ]) %>

  <%- insertFragment('create', [
    '  async create (data, params) {',
    '    if (Array.isArray(data)) {',
    `      return Promise.all(data.map(current => this.create(current, params)))${sc}`,
    '    }',
    '',
    `    return data${sc}`,
    '  }',
  ]) %>

  <%- insertFragment('update', [
    '  async update (id, data, params) {',
    `    return data${sc}`,
    '  }',
  ]) %>

  <%- insertFragment('patch', [
    '  async patch (id, data, params) {',
    `    return data${sc}`,
    '  }',
  ]) %>

  <%- insertFragment('remove', [
    '  async remove (id, params) {',
    `    return { id }${sc}`,
    '  }',
  ]) %>
  <%- insertFragment('more') %>
}

const moduleExports = function (options) {
  return new Service(options)<%- sc %>
}<%- sc %>

moduleExports.Service = Service<%- sc %>

<%- insertFragment('exports') %>
module.exports = moduleExports;

<% } -%>
<%# --- if-1 ends above. -%>
<%# -%>
<%# --- if-2 starts below. TYPESCRIPT ---------------------------------------------------------- -%>
<% if (!isJs) { %>
import { App } from '../../app.interface'<%- sc %>
import { Id, NullableId, Paginated, Params, ServiceMethods, SetupMethod } from '@feathersjs/feathers'<%- sc %>
<%- insertFragment('imports') %>
<%- insertFragment('init') %>

<%- insertFragment('interface', [
  '// tslint:disable-next-line:no-empty-interface',
  'interface ServiceOptions {}'
]) %>

export class Service implements Partial<ServiceMethods<any>>, SetupMethod {
  <%- insertFragment('properties', '  public app!: App;') %>

  constructor (private options: ServiceOptions = {}) {
    <%- insertFragment('constructor1') %>
  }

  <%- insertFragment('setup', [
    '  public setup (app: App, path: string): void {',
    `    this.app = app${sc}`,
    '  }'
  ]) %>

  <%- insertFragment('find', [
    '  public async find(params?: Params): Promise<any[] | Paginated<any>> {',
    `    return []${sc}`,
    '  }',
  ]) %>

  <%- insertFragment('get', [
    '  public async get (id: Id, params?: Params): Promise<any> {',
    '    return {',
    '      id, text: `A new message with ID: ${id}!`',
    `    }${sc}`,
    '  }',
  ]) %>

  <%- insertFragment('create', [
    '  public async create (data: Partial<any> | Array<Partial<any>>, params?: Params): Promise<any> {',
    '    if (Array.isArray(data)) {',
    `      return Promise.all(data.map(current => this.create(current, params)))${sc}`,
    '    }',
    '',
    `    return data${sc}`,
    '  }',
  ]) %>

  <%- insertFragment('update', [
    '  public async update (id: NullableId, data: any, params?: Params): Promise<any> {',
    `    return data${sc}`,
    '  }',
  ]) %>

  <%- insertFragment('patch', [
    '  public async patch (id: NullableId, data: Partial<any>, params?: Params): Promise<any> {',
    `    return data${sc}`,
    '  }',
  ]) %>

  <%- insertFragment('remove', [
    '  public async remove (id: NullableId, params?: Params): Promise<any> {',
    `    return { id }${sc}`,
    '  }',
  ]) %>
  <%- insertFragment('more') %>
}

export default function (options: ServiceOptions) {
  return new Service(options)<%- sc %>
}

<% } -%>
<%# --- if-2 ends above. -%>
<%- insertFragment('funcs') %>
<%- insertFragment('end') %>
