import {{curlyLeft}}{{{callTypeStr}}}{{#if hasCallback}}, sendUnaryData as GrpcSendUnaryData{{/if}}{{curlyRight}} from 'grpc';
import {{curlyLeft}}RpcContext, RpcMiddleware, MiddlewareNext{{curlyRight}} from 'sasdn';
{{#each protoMsgImportPath}}
import {{curlyLeft}}{{#each this}}{{this}}, {{/each}}{{curlyRight}} from '{{{@key}}}';
{{/each}}

export const {{{methodName}}}Handler: RpcMiddleware = async (ctx: RpcContext, next: MiddlewareNext) => {
  let call: {{{callTypeStr}}}{{{callGenerics}}} = ctx.call as {{{callTypeStr}}}{{{callGenerics}}};
{{#if hasCallback}}
  let callback: GrpcSendUnaryData<{{{responseTypeStr}}}> = ctx.callback;
{{/if}}
{{#if hasRequest}}
  let request = call.request as {{{requestTypeStr}}};
{{/if}}

  await next();

  return Promise.resolve();
};