define(["dojo/_base/declare","dijit/_WidgetBase"],function(declare,_WidgetBase) {return declare ("core/validator",[_WidgetBase],{__testSchema:function(args,app,schemaClass) {if(typeof app.schemas[schemaClass][args.schema]==="undefined") {console.error("Unable to load schema");return null;} else {return app.schemas[schemaClass][args.schema];}},validateParam:function(property,value,required,view) {var isValid=true,missing=false,errors=0;if(typeof value==="number") {value=value.toString();} if((value||"")!=="") {if((property.type||"")==="string") {if((property.pattern||"")!="") {var r=new RegExp(property.pattern);if(!r.test(value)) {isValid=false;errors++;}}} else if(property.enum) {if(!~property.enum.indexOf(value)) {isValid=false;errors++;}}} else {if(required) {isValid=false;missing=true}} if((property.dojo_view_id||"")!=="") {if(view) {(view[property.dojo_view_id]||{})._hasBeenBlurred=true;(view[property.dojo_view_id]||{}).validate();}} return{'isValid':isValid,missing:missing};},validateParams:function(args) {var params=args.schema.properties,obj=args['obj'],isValid=true,invalidParams=[],missingParams=[],errorMessages=[],errorMessagesWithProperty={},errors=0,missing=0;const required=args.schema.required||[];for(var k in params) {if(args.param&&args.param!==k) {continue;} var resp;if(obj&&obj[k]) {if(params[k].type==="object") {resp=this.validateParams({schema:params[k],obj:obj[k],});if(!resp.isValid) isValid=false;invalidParams=invalidParams.concat(resp.invalidParams);missingParams=missingParams.concat(resp.missingParams);errorMessages=errorMessages.concat(resp.errorMessages);errorMessagesWithProperty=Object.assign(errorMessagesWithProperty,resp.errorMessagesWithProperty);} else if(params[k].type==="array"&¶ms[k].items&¶ms[k].items.type==="object") {if(required.includes(k)&&(!Array.isArray(obj[k])||obj[k].length===0)) {isValid=false;invalidParams.push(k);missingParams.push(k);} else {obj[k].forEach(v=>{resp=this.validateParams({schema:params[k].items,obj:v,});if(!resp.isValid) isValid=false;invalidParams=invalidParams.concat(resp.invalidParams);missingParams=missingParams.concat(resp.missingParams);errorMessages=errorMessages.concat(resp.errorMessages);errorMessagesWithProperty=Object.assign(errorMessagesWithProperty,resp.errorMessagesWithProperty);});}} else if(params[k].type==="array"&¶ms[k].items) {if(required.includes(k)&&(!Array.isArray(obj[k])||obj[k].length===0)) {isValid=false;invalidParams.push(k);missingParams.push(k);} else {obj[k].forEach(v=>{resp=this.validateParam(params[k].items,v,required.includes(k));if(!resp.isValid) {isValid=false;invalidParams.push(k);errorMessages.push(params[k].items.error_message||k+" – missing or invalid");if(resp.missing) missingParams.push(k);}})}} else {resp=this.validateParam(params[k],obj[k],required.includes(k));if(!resp.isValid) {isValid=false;invalidParams.push(k);errorMessages.push(params[k].error_message||k+" – missing or invalid");if(resp.missing) missingParams.push(k);}}} else if(args.schema.required&&args.schema.required.includes(k)) {isValid=false;missingParams.push(k);}} return{'isValid':isValid,'invalidParams':invalidParams,'missingParams':missingParams,'errorMessages':errorMessages,'errorMessagesWithProperty':errorMessagesWithProperty};},applySchemaToWidgetsInView:function(schema,view,view_widget_map) {for(var key in schema.properties) {if(view_widget_map[key]) {if(schema.properties[key].pattern) {view[view_widget_map[key]].set('pattern',schema.properties[key].pattern);} if(schema.properties[key].missing_message) {view[view_widget_map[key]].set('missingMessage',schema.properties[key].missing_message);} if(schema.properties[key].error_message) {view[view_widget_map[key]].set('invalidMessage',schema.properties[key].invalid_message);} if(schema.required.includes(key)) {view[view_widget_map[key]].set('required',true);} schema.properties[key].dojo_view_id=view_widget_map[key];}}}})});