#
# Copyright 2020 by Delphix
#
# 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.
#

#
# This class has been automatically generated from:
#     /delphix-pgsql-compatibility-criteria.json
#
# Do not edit this file manually!
#

from __future__ import unicode_literals

from delphixpy.v1_9_3.web.objects.CompatibilityCriteria import CompatibilityCriteria
from delphixpy.v1_9_3 import common

class __Undef(object):
    def __repr__(self):
        return "undef"

    def __setattr__(self, name, value):
        raise Exception('Cannot modify attributes of __Undef.')

_UNDEFINED = __Undef()

try:
    TEXT_TYPE = unicode
except NameError:
    TEXT_TYPE = str

class PgSQLCompatibilityCriteria(CompatibilityCriteria):
    """
    *(extends* :py:class:`v1_9_3.web.vo.CompatibilityCriteria` *)* The
    compatibility criteria to use for selecting compatible PgSQL repositories.
    """
    def __init__(self, undef_enabled=True):
        super(PgSQLCompatibilityCriteria, self).__init__()
        self._type = ("PgSQLCompatibilityCriteria", True)
        self._segment_size = (self.__undef__, True)
        self._variant = (self.__undef__, True)
        self._version = (self.__undef__, True)

    API_VERSION = "1.9.3"

    @classmethod
    def from_dict(cls, data, dirty=False, undef_enabled=True):
        obj = super(PgSQLCompatibilityCriteria, cls).from_dict(data, dirty, undef_enabled)
        obj._segment_size = (data.get("segmentSize", obj.__undef__), dirty)
        if obj._segment_size[0] is not None and obj._segment_size[0] is not obj.__undef__:
            assert isinstance(obj._segment_size[0], int), ("Expected one of [u'integer'], but got %s of type %s" % (obj._segment_size[0], type(obj._segment_size[0])))
            common.validate_format(obj._segment_size[0], "None", None, None)
        obj._variant = (data.get("variant", obj.__undef__), dirty)
        if obj._variant[0] is not None and obj._variant[0] is not obj.__undef__:
            assert isinstance(obj._variant[0], TEXT_TYPE), ("Expected one of [u'string'], but got %s of type %s" % (obj._variant[0], type(obj._variant[0])))
            assert obj._variant[0] in [u'PostgreSQL', u'EnterpriseDB'], "Expected enum [u'PostgreSQL', u'EnterpriseDB'] but got %s" % obj._variant[0]
            common.validate_format(obj._variant[0], "None", None, None)
        obj._version = (data.get("version", obj.__undef__), dirty)
        if obj._version[0] is not None and obj._version[0] is not obj.__undef__:
            assert isinstance(obj._version[0], TEXT_TYPE), ("Expected one of [u'string'], but got %s of type %s" % (obj._version[0], type(obj._version[0])))
            common.validate_format(obj._version[0], "pgsqlVersion", None, None)
        return obj

    def to_dict(self, dirty=False, belongs_to_parent=False):
        dct = super(PgSQLCompatibilityCriteria, self).to_dict(dirty, belongs_to_parent)

        def dictify(obj, prop_is_list_or_vo=False):
            if isinstance(obj, list):
                return [dictify(o, prop_is_list_or_vo) for o in obj]
            elif hasattr(obj, "to_dict"):
                return obj.to_dict(dirty=dirty, belongs_to_parent=prop_is_list_or_vo)
            else:
                return obj
        if "segment_size" == "type" or (self.segment_size is not self.__undef__ and (not (dirty and not self._segment_size[1]))):
            dct["segmentSize"] = dictify(self.segment_size)
        if "variant" == "type" or (self.variant is not self.__undef__ and (not (dirty and not self._variant[1]))):
            dct["variant"] = dictify(self.variant)
        if "version" == "type" or (self.version is not self.__undef__ and (not (dirty and not self._version[1]))):
            dct["version"] = dictify(self.version)
        return dct

    def dirty(self):
        return self.from_dict(self.to_dict(dirty=False), dirty=True)

    def force_dirty(self):
        self._segment_size = (self._segment_size[0], True)
        self._variant = (self._variant[0], True)
        self._version = (self._version[0], True)

    def is_dirty(self):
        return any([self._segment_size[1], self._variant[1], self._version[1]])

    def __eq__(self, other):
        if other is None:
            return False
        if not isinstance(other, PgSQLCompatibilityCriteria):
            return False
        return super(PgSQLCompatibilityCriteria, self).__eq__(other) and \
               self.segment_size == other.segment_size and \
               self.variant == other.variant and \
               self.version == other.version

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

    def __hash__(self):
        return id(self)

    def __repr__(self):
        return common.generate_repr_string(self)

    @property
    def segment_size(self):
        """
        Selected repositories have this size WAL segments.

        :rtype: ``int``
        """
        return self._segment_size[0]

    @segment_size.setter
    def segment_size(self, value):
        self._segment_size = (value, True)

    @property
    def variant(self):
        """
        Selected repositories will match this variant of the PostgreSQL
        distribution. *(permitted values: PostgreSQL, EnterpriseDB)*

        :rtype: ``TEXT_TYPE``
        """
        return self._variant[0]

    @variant.setter
    def variant(self, value):
        self._variant = (value, True)

    @property
    def version(self):
        """
        Selected repositories are this database version. In case of upgrade,
        selected repositories are strictly greater than this database version.

        :rtype: ``TEXT_TYPE``
        """
        return self._version[0]

    @version.setter
    def version(self, value):
        self._version = (value, True)

