// -*- 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>

// Refinement templates: the search is NOT complete (0, or more than 1 result), and the
// agent doesn't want to show results
//
// These include proposals, and empty search errors.
// A proposal is when the agent proposed a refined search; the user answers:
// - some form of "yes"
// - some form of "no" followed by another search refinement

import { Ast, } from 'thingtalk';
import * as C from '../../ast_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("empty_search_error");
   $grammar.addRule("empty_search_error", [new $runtime.NonTerminal("sorry_preamble", undefined), new $runtime.Choice(["there are no", "i cannot find any"]), new $runtime.NonTerminal("base_table", undefined), new $runtime.Choice(["matching your request", "with those characteristics", "like that"]), "."], (($0 : string, $1 : undefined, base : Ast.InvocationExpression, $2 : undefined, $3 : undefined) : ([Ast.InvocationExpression|null, C.ParamSlot|null])|null => [base, null]), undefined, {  });
   if (!$options.flags.inference) {
       $grammar.addRule("empty_search_error", [new $runtime.NonTerminal("sorry_preamble", undefined), new $runtime.Choice(["there are no", "i cannot find any"]), new $runtime.NonTerminal("base_table", undefined), new $runtime.Choice(["matching your request", "with those characteristics", "like that"]), ".", "would you like", new $runtime.Choice(["a different", "another"]), new $runtime.NonTerminal("out_param_Any", undefined), "?"], (($0 : string, $1 : undefined, base : Ast.InvocationExpression, $2 : undefined, $3 : undefined, $4 : undefined, $5 : undefined, p : C.ParamSlot, $6 : undefined) : ([Ast.InvocationExpression|null, C.ParamSlot|null])|null => {
            if (!C.isSameFunction(base.schema!, p.schema))
                return null;
            if (p.name === 'id')
                return null;
            return [base, p];
        }), undefined, { priority: (1) });
       $grammar.addRule("empty_search_error", [new $runtime.NonTerminal("sorry_preamble", undefined), "i cannot find any result for your search . would you like", new $runtime.Choice(["a different", "another"]), new $runtime.NonTerminal("out_param_Any", undefined), "?"], (($0 : string, $1 : undefined, $2 : undefined, p : C.ParamSlot, $3 : undefined) : ([Ast.InvocationExpression|null, C.ParamSlot|null])|null => {
            if (p.name === 'id')
                return null;
            return [null, p];
        }), undefined, {  });
   }
   if ($options.flags.inference) {
       $grammar.addRule("empty_search_error", [new $runtime.NonTerminal("sorry_preamble", undefined), "i cannot find any result for your search ."], (($0 : string, $1 : undefined) : ([Ast.InvocationExpression|null, C.ParamSlot|null])|null => [null, null]), undefined, { priority: (-1) });
   }
   $grammar.declareSymbol("precise_empty_search_change_request");
   $grammar.addRule("precise_empty_search_change_request", [new $runtime.Choice(["i see ,", "okay", "okay ,", "yeah", "yeah ,"]), new $runtime.Choice(["do you have", "can you find", "is there", "how about"]), "a", new $runtime.NonTerminal("answer_noun_phrase", undefined), "?"], (($0 : undefined, $1 : undefined, $2 : undefined, phrase : Ast.Expression, $3 : undefined) : (Ast.Expression)|null => phrase), C.expressionKeyFn, {  });
   $grammar.addRule("precise_empty_search_change_request", [new $runtime.Choice(["i see ,", "okay", "okay ,", "yeah", "yeah ,"]), new $runtime.Choice(["do you have", "can you find", "is there", "how about"]), new $runtime.NonTerminal("anything_phrase", undefined), "?"], (($0 : undefined, $1 : undefined, phrase : Ast.Expression, $2 : undefined) : (Ast.Expression)|null => phrase), C.expressionKeyFn, {  });
   $grammar.declareSymbol("imprecise_empty_search_change_request");
   $grammar.addRule("imprecise_empty_search_change_request", [new $runtime.Choice(["i see ,", "okay", "okay ,", "yeah", "yeah ,"]), new $runtime.Choice(["do you have", "can you find", "is there", "how about"]), new $runtime.NonTerminal("imprecise_search_answer_phrase", undefined), "?"], (($0 : undefined, $1 : undefined, answer : Ast.Value|C.FilterSlot, $2 : undefined) : (Ast.Value|C.FilterSlot)|null => answer), undefined, {  });
};
