// Compiled by ClojureScript 1.9.562 {}
goog.provide('weathergen.progress');
goog.require('cljs.core');
weathergen.progress._STAR_reporter_STAR_ = null;
weathergen.progress._STAR_current_step_STAR_ = null;

/**
 * @interface
 */
weathergen.progress.Reporter = function(){};

/**
 * Begins a new logical step in the reported sequence, a child of
 *  `parent` if non-nil. Returns a `Step` instance.
 */
weathergen.progress._start_step = (function weathergen$progress$_start_step(this$,step_name,parent){
if((!((this$ == null))) && (!((this$.weathergen$progress$Reporter$_start_step$arity$3 == null)))){
return this$.weathergen$progress$Reporter$_start_step$arity$3(this$,step_name,parent);
} else {
var x__24056__auto__ = (((this$ == null))?null:this$);
var m__24057__auto__ = (weathergen.progress._start_step[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,this$,step_name,parent);
} else {
var m__24057__auto____$1 = (weathergen.progress._start_step["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__auto____$1.call(null,this$,step_name,parent);
} else {
throw cljs.core.missing_protocol.call(null,"Reporter.-start-step",this$);
}
}
}
});


/**
 * @interface
 */
weathergen.progress.Step = function(){};

/**
 * Reports that the step has succeeded. Implicitly closes the step.
 */
weathergen.progress._succeeded = (function weathergen$progress$_succeeded(this$){
if((!((this$ == null))) && (!((this$.weathergen$progress$Step$_succeeded$arity$1 == null)))){
return this$.weathergen$progress$Step$_succeeded$arity$1(this$);
} else {
var x__24056__auto__ = (((this$ == null))?null:this$);
var m__24057__auto__ = (weathergen.progress._succeeded[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,this$);
} else {
var m__24057__auto____$1 = (weathergen.progress._succeeded["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__auto____$1.call(null,this$);
} else {
throw cljs.core.missing_protocol.call(null,"Step.-succeeded",this$);
}
}
}
});

/**
 * Reports that something nonfatal but of concern has happened.
 */
weathergen.progress._warn = (function weathergen$progress$_warn(this$,message){
if((!((this$ == null))) && (!((this$.weathergen$progress$Step$_warn$arity$2 == null)))){
return this$.weathergen$progress$Step$_warn$arity$2(this$,message);
} else {
var x__24056__auto__ = (((this$ == null))?null:this$);
var m__24057__auto__ = (weathergen.progress._warn[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,this$,message);
} else {
var m__24057__auto____$1 = (weathergen.progress._warn["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__auto____$1.call(null,this$,message);
} else {
throw cljs.core.missing_protocol.call(null,"Step.-warn",this$);
}
}
}
});

/**
 * Reports that the step has failed. Implicitly closes the step.
 */
weathergen.progress._failed = (function weathergen$progress$_failed(this$,message){
if((!((this$ == null))) && (!((this$.weathergen$progress$Step$_failed$arity$2 == null)))){
return this$.weathergen$progress$Step$_failed$arity$2(this$,message);
} else {
var x__24056__auto__ = (((this$ == null))?null:this$);
var m__24057__auto__ = (weathergen.progress._failed[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,this$,message);
} else {
var m__24057__auto____$1 = (weathergen.progress._failed["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__auto____$1.call(null,this$,message);
} else {
throw cljs.core.missing_protocol.call(null,"Step.-failed",this$);
}
}
}
});

/**
 * Returns this step's id, if any.
 */
weathergen.progress._id = (function weathergen$progress$_id(this$){
if((!((this$ == null))) && (!((this$.weathergen$progress$Step$_id$arity$1 == null)))){
return this$.weathergen$progress$Step$_id$arity$1(this$);
} else {
var x__24056__auto__ = (((this$ == null))?null:this$);
var m__24057__auto__ = (weathergen.progress._id[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,this$);
} else {
var m__24057__auto____$1 = (weathergen.progress._id["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__auto____$1.call(null,this$);
} else {
throw cljs.core.missing_protocol.call(null,"Step.-id",this$);
}
}
}
});

/**
 * Reports progress via `*reporter*`, if bound.
 */
weathergen.progress.report = (function weathergen$progress$report(message){
if(cljs.core.truth_(weathergen.progress._STAR_reporter_STAR_)){
return weathergen.progress._STAR_reporter_STAR_.call(null,message);
} else {
return null;
}
});
/**
 * Reports that `step-name` has started. Returns a `Step` instance.
 */
weathergen.progress.start_step = (function weathergen$progress$start_step(step_name,parent){
if(cljs.core.truth_(weathergen.progress._STAR_reporter_STAR_)){
return weathergen.progress._start_step.call(null,weathergen.progress._STAR_reporter_STAR_,step_name,parent);
} else {
return null;
}
});
/**
 * Reports that step has succeeded. If no step is provided, uses
 *   `*current-step*`.
 */
weathergen.progress.step_succeeded = (function weathergen$progress$step_succeeded(var_args){
var args35028 = [];
var len__24559__auto___35031 = arguments.length;
var i__24560__auto___35032 = (0);
while(true){
if((i__24560__auto___35032 < len__24559__auto___35031)){
args35028.push((arguments[i__24560__auto___35032]));

var G__35033 = (i__24560__auto___35032 + (1));
i__24560__auto___35032 = G__35033;
continue;
} else {
}
break;
}

var G__35030 = args35028.length;
switch (G__35030) {
case 0:
return weathergen.progress.step_succeeded.cljs$core$IFn$_invoke$arity$0();

break;
case 1:
return weathergen.progress.step_succeeded.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
default:
throw (new Error([cljs.core.str.cljs$core$IFn$_invoke$arity$1("Invalid arity: "),cljs.core.str.cljs$core$IFn$_invoke$arity$1(args35028.length)].join('')));

}
});

weathergen.progress.step_succeeded.cljs$core$IFn$_invoke$arity$0 = (function (){
return weathergen.progress.step_succeeded.call(null,weathergen.progress._STAR_current_step_STAR_);
});

weathergen.progress.step_succeeded.cljs$core$IFn$_invoke$arity$1 = (function (step){
if(cljs.core.truth_(step)){
return weathergen.progress._succeeded.call(null,step);
} else {
return null;
}
});

weathergen.progress.step_succeeded.cljs$lang$maxFixedArity = 1;

/**
 * Reports a warning against `step`, or `*current-step*` if one is not
 *   provided.
 */
weathergen.progress.step_warn = (function weathergen$progress$step_warn(var_args){
var args35035 = [];
var len__24559__auto___35038 = arguments.length;
var i__24560__auto___35039 = (0);
while(true){
if((i__24560__auto___35039 < len__24559__auto___35038)){
args35035.push((arguments[i__24560__auto___35039]));

var G__35040 = (i__24560__auto___35039 + (1));
i__24560__auto___35039 = G__35040;
continue;
} else {
}
break;
}

var G__35037 = args35035.length;
switch (G__35037) {
case 1:
return weathergen.progress.step_warn.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
case 2:
return weathergen.progress.step_warn.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
default:
throw (new Error([cljs.core.str.cljs$core$IFn$_invoke$arity$1("Invalid arity: "),cljs.core.str.cljs$core$IFn$_invoke$arity$1(args35035.length)].join('')));

}
});

weathergen.progress.step_warn.cljs$core$IFn$_invoke$arity$1 = (function (message){
return weathergen.progress.step_warn.call(null,weathergen.progress._STAR_current_step_STAR_,message);
});

weathergen.progress.step_warn.cljs$core$IFn$_invoke$arity$2 = (function (step,message){
if(cljs.core.truth_(step)){
return weathergen.progress._warn.call(null,step,message);
} else {
return null;
}
});

weathergen.progress.step_warn.cljs$lang$maxFixedArity = 2;

/**
 * Reports that `step` has failed. Uses `*current-step*` if one is not
 *   provided.
 */
weathergen.progress.step_failed = (function weathergen$progress$step_failed(var_args){
var args35042 = [];
var len__24559__auto___35045 = arguments.length;
var i__24560__auto___35046 = (0);
while(true){
if((i__24560__auto___35046 < len__24559__auto___35045)){
args35042.push((arguments[i__24560__auto___35046]));

var G__35047 = (i__24560__auto___35046 + (1));
i__24560__auto___35046 = G__35047;
continue;
} else {
}
break;
}

var G__35044 = args35042.length;
switch (G__35044) {
case 1:
return weathergen.progress.step_failed.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
case 2:
return weathergen.progress.step_failed.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
default:
throw (new Error([cljs.core.str.cljs$core$IFn$_invoke$arity$1("Invalid arity: "),cljs.core.str.cljs$core$IFn$_invoke$arity$1(args35042.length)].join('')));

}
});

weathergen.progress.step_failed.cljs$core$IFn$_invoke$arity$1 = (function (message){
return weathergen.progress.step_failed.call(null,weathergen.progress._STAR_current_step_STAR_,message);
});

weathergen.progress.step_failed.cljs$core$IFn$_invoke$arity$2 = (function (step,message){
if(cljs.core.truth_(step)){
return weathergen.progress._failed.call(null,step,message);
} else {
return null;
}
});

weathergen.progress.step_failed.cljs$lang$maxFixedArity = 2;

/**
 * Binds `*current-step*` to a new step calls `f`, a function of no
 *   arguments.
 */
weathergen.progress.with_step = (function weathergen$progress$with_step(step_name,f){
var step = weathergen.progress.start_step.call(null,step_name,weathergen.progress._STAR_current_step_STAR_);
var _STAR_current_step_STAR_35053 = weathergen.progress._STAR_current_step_STAR_;
weathergen.progress._STAR_current_step_STAR_ = step;

try{try{var val = f.call(null);
weathergen.progress.step_succeeded.call(null);

return val;
}catch (e35054){var x = e35054;
console.error("Caught error","propagated?",cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"type","type",1174270348).cljs$core$IFn$_invoke$arity$1(cljs.core.ex_data.call(null,x)),new cljs.core.Keyword("weathergen.progress","propagated-error","weathergen.progress/propagated-error",1931683700)),":x",x,":data",cljs.core.ex_data.call(null,x));

weathergen.progress.step_failed.call(null,(function (){var map__35055 = cljs.core.ex_data.call(null,x);
var map__35055__$1 = ((((!((map__35055 == null)))?((((map__35055.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35055.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35055):map__35055);
var type = cljs.core.get.call(null,map__35055__$1,new cljs.core.Keyword(null,"type","type",1174270348));
var omit_stack_trace_QMARK_ = cljs.core.get.call(null,map__35055__$1,new cljs.core.Keyword(null,"omit-stack-trace?","omit-stack-trace?",1080142229));
if(cljs.core._EQ_.call(null,type,new cljs.core.Keyword("weathergen.progress","propagated-error","weathergen.progress/propagated-error",1931683700))){
return null;
} else {
if(cljs.core.truth_(omit_stack_trace_QMARK_)){
return x.message;
} else {
return x.stack;

}
}
})());

throw cljs.core.ex_info.call(null,"Propagated error",new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"type","type",1174270348),new cljs.core.Keyword("weathergen.progress","propagated-error","weathergen.progress/propagated-error",1931683700)], null),x);
}}finally {weathergen.progress._STAR_current_step_STAR_ = _STAR_current_step_STAR_35053;
}});
