# -*- coding: utf-8 -*-

###############################################################################
#
# GetSearchResult
# Allows your application to submit a query to Wolfram|Alpha and return only the plain text from the first result pod.
#
# Python versions 2.6, 2.7, 3.x
#
# Copyright 2014, Temboo Inc.
#
# 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.
#
#
###############################################################################

from temboo.core.choreography import Choreography
from temboo.core.choreography import InputSet
from temboo.core.choreography import ResultSet
from temboo.core.choreography import ChoreographyExecution

import json

class GetSearchResult(Choreography):

    def __init__(self, temboo_session):
        """
        Create a new instance of the GetSearchResult Choreo. A TembooSession object, containing a valid
        set of Temboo credentials, must be supplied.
        """
        super(GetSearchResult, self).__init__(temboo_session, '/Library/WolframAlpha/GetSearchResult')


    def new_input_set(self):
        return GetSearchResultInputSet()

    def _make_result_set(self, result, path):
        return GetSearchResultResultSet(result, path)

    def _make_execution(self, session, exec_id, path):
        return GetSearchResultChoreographyExecution(session, exec_id, path)

class GetSearchResultInputSet(InputSet):
    """
    An InputSet with methods appropriate for specifying the inputs to the GetSearchResult
    Choreo. The InputSet object is used to specify input parameters when executing this Choreo.
    """
    def set_AppID(self, value):
        """
        Set the value of the AppID input for this Choreo. ((required, string) The App ID provided by Wolfram|Alpha.)
        """
        super(GetSearchResultInputSet, self)._set_input('AppID', value)
    def set_Input(self, value):
        """
        Set the value of the Input input for this Choreo. ((required, string) Specifies the input string (e.g., "5 largest countries").)
        """
        super(GetSearchResultInputSet, self)._set_input('Input', value)
    def set_Latitude(self, value):
        """
        Set the value of the Latitude input for this Choreo. ((optional, decimal) When query results depend on your location, use this parameter to specify a latitude point.)
        """
        super(GetSearchResultInputSet, self)._set_input('Latitude', value)
    def set_Location(self, value):
        """
        Set the value of the Location input for this Choreo. ((optional, string) When query results depend on your location, use this parameter to specify a location such as "Los Angeles, CA", or "Madrid".)
        """
        super(GetSearchResultInputSet, self)._set_input('Location', value)
    def set_Longitude(self, value):
        """
        Set the value of the Longitude input for this Choreo. ((optional, decimal) When query results depend on your location, use this parameter to specify a longitude point.)
        """
        super(GetSearchResultInputSet, self)._set_input('Longitude', value)
    def set_ResponseFormat(self, value):
        """
        Set the value of the ResponseFormat input for this Choreo. ((optional, string) The format for the response. Valid values are JSON and XML. This will be ignored when providng an XPath query because results are returned as a string or JSON depending on the Mode specified.)
        """
        super(GetSearchResultInputSet, self)._set_input('ResponseFormat', value)
    def set_Translation(self, value):
        """
        Set the value of the Translation input for this Choreo. ((optional, boolean) Whether to allow Wolfram Alpha to try to translate simple queries into English. Defaults to true.)
        """
        super(GetSearchResultInputSet, self)._set_input('Translation', value)
    def set_Units(self, value):
        """
        Set the value of the Units input for this Choreo. ((optional, string) Lets you specify the preferred measurement system, either "metric" or "nonmetric" (U.S. customary units).)
        """
        super(GetSearchResultInputSet, self)._set_input('Units', value)

class GetSearchResultResultSet(ResultSet):
    """
    A ResultSet with methods tailored to the values returned by the GetSearchResult Choreo.
    The ResultSet object is used to retrieve the results of a Choreo execution.
    """

    def getJSONFromString(self, str):
        return json.loads(str)

    def get_Result(self):
        """
        Retrieve the value for the "Result" output from this Choreo execution. ((string) The plain text result parsed from the Wolfram Alpha response.)
        """
        return self._output.get('Result', None)

class GetSearchResultChoreographyExecution(ChoreographyExecution):

    def _make_result_set(self, response, path):
        return GetSearchResultResultSet(response, path)
