// -*- mode: typescript; 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>

// List proposal templates: the search is complete (1-3 search results), and the
// agent reads out the search results, optionally proposing an action to do on them

// A list proposal from the system is followed by:
// - choosing an element from the list (= "positive_list_proposal_reply_pair")
// - some form of search refinement (= "negative_list_proposa_reply_pair")
// - a question about an element of the list (= "list_proposal_search_question_pair")

import { Ast, } from 'thingtalk';
import * as C from '../../ast_manip';
import * as D from '../../dialogue_acts';
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("system_list_proposal");
   if (!$options.flags.inference) {
       $grammar.addRule("system_list_proposal", [new $runtime.Choice(["i see", "i have", "i have found"]), new $runtime.NonTerminal("result_name_list", undefined), ".", new $runtime.Choice(["", "would you like to learn more ?", "would you like to learn more about either of them ?", "would you like to know more about them ?", "would you like to hear more about them ?", "are you interested to hear more about any of them ?"])], (($0 : undefined, name_list : D.NameList, $1 : undefined, $2 : undefined) : (D.ListProposal)|null => D.checkListProposal(name_list, null, true)), D.listProposalKeyFn, {  });
   }
   if ($options.flags.inference) {
       $grammar.addRule("system_list_proposal", [new $runtime.Choice(["i see", "i have", "i have found"]), new $runtime.NonTerminal("result_name_list", undefined), "."], (($0 : undefined, name_list : D.NameList, $1 : undefined) : (D.ListProposal)|null => D.checkListProposal(name_list, null, true)), D.listProposalKeyFn, {  });
   }
   $grammar.addRule("system_list_proposal", [new $runtime.Choice(["i see", "i have", "i have found"]), new $runtime.NonTerminal("result_name_list", undefined), ".", new $runtime.Choice(["they", "all of them"]), "are", new $runtime.NonTerminal("result_info_phrase", undefined), "."], (($0 : undefined, name_list : D.NameList, $1 : undefined, $2 : undefined, $3 : undefined, res : D.ResultPhrase, $4 : undefined) : (D.ListProposal)|null => D.checkListProposal(name_list, res.info, true)), D.listProposalKeyFn, { priority: (2) });
   $grammar.addRule("system_list_proposal", [new $runtime.Choice(["i see", "i have", "i have found"]), new $runtime.NonTerminal("result_name_list", undefined), ".", "both are", new $runtime.NonTerminal("result_info_phrase", undefined), "."], (($0 : undefined, name_list : D.NameList, $1 : undefined, $2 : undefined, res : D.ResultPhrase, $3 : undefined) : (D.ListProposal)|null => {
        if (name_list.results.length !== 2)
            return null;
        return D.checkListProposal(name_list, res.info, true);
    }), D.listProposalKeyFn, {  });
   if (!$options.flags.inference) {
       $grammar.addRule("system_list_proposal", [new $runtime.Choice(["i see", "i have", "i have found"]), new $runtime.NonTerminal("result_name_list", undefined), ".", new $runtime.NonTerminal("action_coref_list_proposal", undefined)], (($0 : undefined, name_list : D.NameList, $1 : undefined, action : Ast.Invocation) : (D.ListProposal)|null => D.addActionToListProposal(name_list, action)), D.listProposalKeyFn, { priority: (-1) });
   }
   $grammar.declareSymbol("generic_list_proposal_accept_phrase");
   $grammar.addRule("generic_list_proposal_accept_phrase", [new $runtime.Choice(["ok", "yeah", ""]), new $runtime.Choice(["i like", "i am interested in", "i am intrigued by"]), new $runtime.NonTerminal("constant_name", undefined), "."], (($0 : undefined, $1 : undefined, name : Ast.EntityValue|Ast.NumberValue, $2 : undefined) : (Ast.EntityValue|Ast.NumberValue)|null => name), C.entityOrNumberValueKeyFn, {  });
   $grammar.addRule("generic_list_proposal_accept_phrase", [new $runtime.Choice(["ok", "yeah", ""]), new $runtime.NonTerminal("constant_name", undefined), "sounds", new $runtime.Choice(["good", "really good", "nice", "interesting"]), "."], (($0 : undefined, name : Ast.EntityValue|Ast.NumberValue, $1 : undefined, $2 : undefined, $3 : undefined) : (Ast.EntityValue|Ast.NumberValue)|null => name), C.entityOrNumberValueKeyFn, {  });
   $grammar.declareSymbol("list_proposal_accept_phrase_must_have_action");
   $grammar.addRule("list_proposal_accept_phrase_must_have_action", [new $runtime.Choice(["ok", "yeah", ""]), new $runtime.Choice(["i will go", "i will take", "i am good for"]), new $runtime.NonTerminal("constant_name", undefined), "."], (($0 : undefined, $1 : undefined, name : Ast.EntityValue|Ast.NumberValue, $2 : undefined) : (Ast.EntityValue|Ast.NumberValue)|null => name), C.entityOrNumberValueKeyFn, {  });
   $grammar.declareSymbol("list_proposal_accept_phrase_with_action");
   $grammar.addRule("list_proposal_accept_phrase_with_action", [new $runtime.NonTerminal("generic_list_proposal_accept_phrase", undefined), new $runtime.NonTerminal("generic_preamble_for_action", undefined), new $runtime.NonTerminal("coref_action_command", undefined)], ((name : Ast.EntityValue|Ast.NumberValue, $0 : string, action : Ast.Invocation) : ([Ast.EntityValue|Ast.NumberValue, Ast.Invocation, boolean])|null => [name, action, false]), undefined, {  });
   $grammar.addRule("list_proposal_accept_phrase_with_action", [new $runtime.NonTerminal("list_proposal_accept_phrase_must_have_action", undefined), new $runtime.NonTerminal("generic_preamble_for_action", undefined), new $runtime.NonTerminal("coref_action_command", undefined)], ((name : Ast.EntityValue|Ast.NumberValue, $0 : string, action : Ast.Invocation) : ([Ast.EntityValue|Ast.NumberValue, Ast.Invocation, boolean])|null => [name, action, false]), undefined, {  });
   $grammar.declareSymbol("list_proposal_accept_phrase_with_action_by_name");
   $grammar.addRule("list_proposal_accept_phrase_with_action_by_name", [new $runtime.Choice(["ok", "yeah", ""]), new $runtime.NonTerminal("generic_preamble_for_action", undefined), new $runtime.NonTerminal("action_by_name_command", undefined)], (($0 : undefined, $1 : string, action : Ast.Invocation) : (Ast.Invocation)|null => action), C.invocationKeyFn, {  });
   $grammar.declareSymbol("list_proposal_tell_me_more");
   $grammar.addRule("list_proposal_tell_me_more", [new $runtime.Choice(["ok", "yeah", ""]), "can you tell me more about", new $runtime.NonTerminal("constant_name", undefined), "?"], (($0 : undefined, $1 : undefined, name : Ast.EntityValue|Ast.NumberValue, $2 : undefined) : (Ast.EntityValue|Ast.NumberValue)|null => name), C.entityOrNumberValueKeyFn, {  });
   $grammar.addRule("list_proposal_tell_me_more", [new $runtime.Choice(["ok", "yeah", ""]), new $runtime.Choice(["i like", "i am interested in", "i am intrigued by"]), new $runtime.NonTerminal("constant_name", undefined), ".", new $runtime.NonTerminal("tell_me_more_phrase", undefined)], (($0 : undefined, $1 : undefined, name : Ast.EntityValue|Ast.NumberValue, $2 : undefined, $3 : string) : (Ast.EntityValue|Ast.NumberValue)|null => name), C.entityOrNumberValueKeyFn, {  });
   $grammar.addRule("list_proposal_tell_me_more", [new $runtime.Choice(["ok", "yeah", ""]), new $runtime.NonTerminal("constant_name", undefined), "sounds", new $runtime.Choice(["good", "really good", "nice", "interesting"]), ".", new $runtime.NonTerminal("tell_me_more_phrase", undefined)], (($0 : undefined, name : Ast.EntityValue|Ast.NumberValue, $1 : undefined, $2 : undefined, $3 : undefined, $4 : string) : (Ast.EntityValue|Ast.NumberValue)|null => name), C.entityOrNumberValueKeyFn, {  });
   $grammar.declareSymbol("positive_list_proposal_reply");
   $grammar.addRule("positive_list_proposal_reply", [new $runtime.NonTerminal("generic_list_proposal_accept_phrase", undefined)], ((name : Ast.EntityValue|Ast.NumberValue) : ([Ast.EntityValue|Ast.NumberValue, Ast.Invocation|null, boolean])|null => [name, null, false]), undefined, {  });
   $grammar.addRule("positive_list_proposal_reply", [new $runtime.NonTerminal("list_proposal_accept_phrase_must_have_action", undefined)], ((name : Ast.EntityValue|Ast.NumberValue) : ([Ast.EntityValue|Ast.NumberValue, Ast.Invocation|null, boolean])|null => [name, null, true]), undefined, {  });
   $grammar.addRule("positive_list_proposal_reply", [new $runtime.NonTerminal("list_proposal_accept_phrase_with_action", undefined)], ((accept : [Ast.EntityValue|Ast.NumberValue, Ast.Invocation, boolean]) : ([Ast.EntityValue|Ast.NumberValue, Ast.Invocation|null, boolean])|null => accept), undefined, {  });
};
