import { Service, Inject, Container } from 'typedi';
import initLogger, {LoggerContext} from 'jsm-logger';
import exceptions from 'jsm-exceptions';
import Joi from "joi";

type EntityAlias = {{orAny ENTITY_TYPING_ALIAS}};

const logger = initLogger(LoggerContext.VALIDATOR, '{{ENTITY_CAMELCASED_CAPITALIZED_SINGULAR}}');

{{#each MODULE.API.METHODS}}
{{#ifMethodHasValidator this}}
/**
  * {{serviceMethodComments this}}
  */
export async function validate{{this.name}}Body({{sanitizerArgs this}}): Promise<Joi.ValidationResult<Jsm.Core.Utils.PropType<{{orAny this.requestFullName}}, 'data'>>> {
  if (!body.data) throw new exceptions.ValidationException('Body data object is required');
  const schema = Joi.object<Jsm.Core.Utils.PropType<{{orAny this.requestFullName}}, 'data'>>({
    /**
      * @description Add your validation logic here
      */
    {{validatorSchemaFields ../this this}}
  });
  
  return schema.validate(body.data, {
    abortEarly: false,
    allowUnknown: true
  });
}
  {{nl}}
{{/ifMethodHasValidator}}
{{/each}}