// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of Genie
//
// Copyright 2020 The Board of Trustees of the Leland Stanford Junior University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Giovanni Campagna <gcampagn@cs.stanford.edu>

// Templates that describe results from a query

import { Ast, } from 'thingtalk';
import * as C from '../../ast_manip';
import * as D from '../../dialogue_acts';
import * as S from '../../state_manip';
import ThingpediaLoader from '../../load-thingpedia';
import type * as $Genie from "genie-toolkit";
export default async function($runtime : typeof $Genie.SentenceGeneratorRuntime, $ttUtils : typeof $Genie.ThingTalkUtils, $options : $Genie.SentenceGeneratorTypes.GrammarOptions, $locale : $Genie.I18n.LanguagePack, $grammar : $Genie.SentenceGenerator<any, any>, $loader : ThingpediaLoader) : Promise<void> {
   $grammar.declareSymbol("count_aggregation_reply_suffix");
   $grammar.addRule("count_aggregation_reply_suffix", [new $runtime.NonTerminal("ctx_with_aggregation_result", undefined), new $runtime.NonTerminal("base_table", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)]), new $runtime.Choice(["like that", "with those characteristics"])], ((ctx : S.ContextInfo, base : Ast.InvocationExpression, $0 : undefined) : (S.ContextInfo)|null => D.makeCountAggregationReplySuffix(ctx, base, false)), S.contextKeyFn, {  });
   $grammar.addRule("count_aggregation_reply_suffix", [new $runtime.NonTerminal("ctx_with_aggregation_result", undefined), new $runtime.NonTerminal("one_with_filter_table", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, table : Ast.Expression) : (S.ContextInfo)|null => D.makeCountAggregationReplySuffix(ctx, table, true)), S.contextKeyFn, { priority: (10) });
   $grammar.addRule("count_aggregation_reply_suffix", [new $runtime.NonTerminal("ctx_with_aggregation_result", undefined), new $runtime.NonTerminal("two_with_filter_table", ["functionName" as ("functionName" extends keyof ReturnType<typeof C.expressionKeyFn> ? string : void), 0, "currentFunction" as ("currentFunction" extends keyof ReturnType<typeof S.contextKeyFn> ? string : void)])], ((ctx : S.ContextInfo, table : Ast.Expression) : (S.ContextInfo)|null => D.makeCountAggregationReplySuffix(ctx, table, true)), S.contextKeyFn, { priority: (10) });
   $grammar.declareSymbol("count_aggregation_reply");
   $grammar.addRule("count_aggregation_reply", [new $runtime.Choice(["there are", "i see", "i have"]), new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("count_aggregation_reply_suffix", undefined)], (($0 : undefined, num : Ast.NumberValue, ctx : S.ContextInfo) : (S.AgentReplyRecord)|null => D.makeCountAggregationReply(ctx, num)), undefined, {  });
   $grammar.declareSymbol("agg_operator_for_reply");
   $grammar.addRule("agg_operator_for_reply", ["minimum"], (($0 : undefined) : ('min'|'max'|'avg'|'sum')|null => 'min'), undefined, {  });
   $grammar.addRule("agg_operator_for_reply", ["smallest"], (($0 : undefined) : ('min'|'max'|'avg'|'sum')|null => 'min'), undefined, {  });
   $grammar.addRule("agg_operator_for_reply", ["maximum"], (($0 : undefined) : ('min'|'max'|'avg'|'sum')|null => 'max'), undefined, {  });
   $grammar.addRule("agg_operator_for_reply", ["largest"], (($0 : undefined) : ('min'|'max'|'avg'|'sum')|null => 'max'), undefined, {  });
   $grammar.addRule("agg_operator_for_reply", ["average"], (($0 : undefined) : ('min'|'max'|'avg'|'sum')|null => 'avg'), undefined, {  });
   $grammar.addRule("agg_operator_for_reply", ["total"], (($0 : undefined) : ('min'|'max'|'avg'|'sum')|null => 'sum'), undefined, {  });
   $grammar.declareSymbol("other_aggregation_reply");
   $grammar.addRule("other_aggregation_reply", [new $runtime.NonTerminal("ctx_with_aggregation_result", undefined), "the", new $runtime.NonTerminal("agg_operator_for_reply", undefined), new $runtime.NonTerminal("out_param_Any", undefined), "is", new $runtime.NonTerminal("constant_Any", undefined)], ((ctx : S.ContextInfo, $0 : undefined, op : 'min'|'max'|'avg'|'sum', p : C.ParamSlot, $1 : undefined, c : Ast.Value) : (S.AgentReplyRecord)|null => D.makeOtherAggregationReply(ctx, op, p, c)), undefined, {  });
};
