# Copyright 2015 Google Inc. All Rights Reserved.
#
# 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.

"""Base template using which the apis_map.py is generated."""


class APIDef(object):
  """Struct for info required to instantiate clients/messages for API versions.

  Attributes:
    client_classpath: str, Path to the client class for an API version.
    messages_modulepath: str, Path to the messages module for an API version.
    default_version: bool, Whether this API version is the default version for
    the API.
  """

  def __init__(self,
               client_classpath,
               messages_modulepath,
               default_version=False):
    self.client_classpath = client_classpath
    self.messages_modulepath = messages_modulepath
    self.default_version = default_version

  def __eq__(self, other):
    return (isinstance(other, self.__class__)
            and self.__dict__ == other.__dict__)

  def __ne__(self, other):
    return not self.__eq__(other)

  def get_init_source(self):
    src_fmt = 'APIDef("{0}", "{1}", {2})'
    return src_fmt.format(self.client_classpath, self.messages_modulepath,
                          self.default_version)

  def __repr__(self):
    return self.get_init_source()


MAP = {
    'banana': {
        'v2_staging': APIDef(
            client_classpath='plants.fruits.banana.v2_staging.banana_v2_client.BananaV2',
            messages_modulepath='plants.fruits.banana.v2_staging.banana_v2_messages',
            default_version=True
        ),
        'v2beta': APIDef(
            client_classpath='plants.fruits.banana.v2beta.banana_v2beta_client.BananaV2beta',
            messages_modulepath='plants.fruits.banana.v2beta.banana_v2beta_messages',
            default_version=False
        ),
    },
    'orange': {
        'v1': APIDef(
            client_classpath='plants.fruits.orange.v1.orange_v1_client.OrangeV1',
            messages_modulepath='plants.fruits.orange.v1.orange_v1_messages',
            default_version=True
        ),
        'v2': APIDef(
            client_classpath='plants.fruits.orange.v2.orange_v2_client.OrangeV2',
            messages_modulepath='plants.fruits.orange.v2.orange_v2_messages',
            default_version=False
        ),
    },
    'pear': {
        'v7_test': APIDef(
            client_classpath='plants.fruits.pear.v7_test.pear_v7_test_client.PearV7Test',
            messages_modulepath='plants.fruits.pear.v7_test.pear_v7_test_messages',
            default_version=True
        ),
    },
}
