# Leviton Cloud Services API model ManagementTier.
# Auto-generated by api_scraper.py.
#
# Copyright 2017 Tim Lyakhovetskiy <tlyakhov@gmail.com>
#
# This code is released under the terms of the MIT license. See the LICENSE
# file for more details.
from decora_wifi.base_model import BaseModel


class ManagementTier(BaseModel):
    def __init__(self, session, model_id=None):
        super(ManagementTier, self).__init__(session, model_id)

    @classmethod
    def count(cls, session, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/count"
        return session.call_api(api, attribs, 'get')

    def count_feed_items(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/feedItems/count".format(self._id)
        return self._session.call_api(api, attribs, 'get')

    def count_locations(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/locations/count".format(self._id)
        return self._session.call_api(api, attribs, 'get')

    def count_management_tier_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers/count".format(self._id)
        return self._session.call_api(api, attribs, 'get')

    def count_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers/count".format(self._id)
        return self._session.call_api(api, attribs, 'get')

    def count_people(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/people/count".format(self._id)
        return self._session.call_api(api, attribs, 'get')

    def count_permissions(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/permissions/count".format(self._id)
        return self._session.call_api(api, attribs, 'get')

    @classmethod
    def create(cls, session, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers"
        return session.call_api(api, attribs, 'post')

    def create_feed_items(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/feedItems".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    def create_locations(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/locations".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    def create_management_tier_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    def create_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    @classmethod
    def create_many(cls, session, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers"
        return session.call_api(api, attribs, 'post')

    def create_many_management_tier_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    def create_people(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/people".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    def create_permissions(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/permissions".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    def delete_by_id(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}".format(self._id)
        return self._session.call_api(api, attribs, 'delete')

    def delete_feed_items(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/feedItems".format(self._id)
        return self._session.call_api(api, attribs, 'delete')

    def delete_locations(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/locations".format(self._id)
        return self._session.call_api(api, attribs, 'delete')

    def delete_management_tier_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers".format(self._id)
        return self._session.call_api(api, attribs, 'delete')

    def delete_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers".format(self._id)
        return self._session.call_api(api, attribs, 'delete')

    def delete_people(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/people".format(self._id)
        return self._session.call_api(api, attribs, 'delete')

    def delete_permissions(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/permissions".format(self._id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_feed_items(self, feed_item_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/feedItems/{1}".format(self._id, feed_item_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_locations(self, location_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/locations/{1}".format(self._id, location_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_management_tier_management_tiers(self, management_tier_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers/{1}".format(self._id, management_tier_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_management_tiers(self, management_tier_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers/{1}".format(self._id, management_tier_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_people(self, person_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/people/{1}".format(self._id, person_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_permissions(self, permission_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/permissions/{1}".format(self._id, permission_id)
        return self._session.call_api(api, attribs, 'delete')

    def exists(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/exists".format(self._id)
        return self._session.call_api(api, attribs, 'get')

    def exists_people(self, person_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/people/rel/{1}".format(self._id, person_id)
        return self._session.call_api(api, attribs, 'head')

    @classmethod
    def find(cls, session, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers"
        items = session.call_api(api, attribs, 'get')

        result = []
        if items is not None:
            for data in items:
                model = ManagementTier(session, data['id'])
                model.data = data
                result.append(model)
        return result

    def find_by_id(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}".format(self._id)
        data = self._session.call_api(api, attribs, 'get')

        self.data.update(data)
        return self

    def find_by_id_feed_items(self, feed_item_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/feedItems/{1}".format(self._id, feed_item_id)
        data = self._session.call_api(api, attribs, 'get')

        from .feed_item import FeedItem
        model = FeedItem(self._session, data['id'])
        model.data = data
        return model

    def find_by_id_locations(self, location_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/locations/{1}".format(self._id, location_id)
        data = self._session.call_api(api, attribs, 'get')

        from .location import Location
        model = Location(self._session, data['id'])
        model.data = data
        return model

    def find_by_id_management_tier_management_tiers(self, management_tier_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers/{1}".format(self._id, management_tier_id)
        data = self._session.call_api(api, attribs, 'get')

        self.data.update(data)
        return self

    def find_by_id_management_tiers(self, management_tier_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers/{1}".format(self._id, management_tier_id)
        data = self._session.call_api(api, attribs, 'get')

        self.data.update(data)
        return self

    def find_by_id_people(self, person_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/people/{1}".format(self._id, person_id)
        data = self._session.call_api(api, attribs, 'get')

        from .person import Person
        model = Person(self._session, data['id'])
        model.data = data
        return model

    def find_by_id_permissions(self, permission_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/permissions/{1}".format(self._id, permission_id)
        data = self._session.call_api(api, attribs, 'get')

        from .permission import Permission
        model = Permission(self._session, data['id'])
        model.data = data
        return model

    @classmethod
    def find_one(cls, session, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/findOne"
        return session.call_api(api, attribs, 'get')

    def refresh(self):
        api = "/ManagementTiers/{0}".format(self._id)
        result = self._session.call_api(api, {}, 'get')
        if result is not None:
            self.data.update(result)
        return self

    def get_feed_items(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/feedItems".format(self._id)
        items = self._session.call_api(api, attribs, 'get')

        from .feed_item import FeedItem
        result = []
        if items is not None:
            for data in items:
                model = FeedItem(self._session, data['id'])
                model.data = data
                result.append(model)
        return result

    def get_locations(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/locations".format(self._id)
        items = self._session.call_api(api, attribs, 'get')

        from .location import Location
        result = []
        if items is not None:
            for data in items:
                model = Location(self._session, data['id'])
                model.data = data
                result.append(model)
        return result

    def get_management_tier(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTier".format(self._id)
        data = self._session.call_api(api, attribs, 'get')

        self.data.update(data)
        return self

    def get_management_tier_management_tier(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTier".format(self._id)
        data = self._session.call_api(api, attribs, 'get')

        self.data.update(data)
        return self

    def get_management_tier_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers".format(self._id)
        items = self._session.call_api(api, attribs, 'get')

        self.data.update(data)
        return self

    def get_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers".format(self._id)
        items = self._session.call_api(api, attribs, 'get')

        self.data.update(data)
        return self

    def get_organization(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/organization".format(self._id)
        data = self._session.call_api(api, attribs, 'get')

        from .organization import Organization
        model = Organization(self._session, data['id'])
        model.data = data
        return model

    def get_people(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/people".format(self._id)
        items = self._session.call_api(api, attribs, 'get')

        from .person import Person
        result = []
        if items is not None:
            for data in items:
                model = Person(self._session, data['id'])
                model.data = data
                result.append(model)
        return result

    def get_permissions(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/permissions".format(self._id)
        items = self._session.call_api(api, attribs, 'get')

        from .permission import Permission
        result = []
        if items is not None:
            for data in items:
                model = Permission(self._session, data['id'])
                model.data = data
                result.append(model)
        return result

    def link_people(self, person_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/people/rel/{1}".format(self._id, person_id)
        data = self._session.call_api(api, attribs, 'put')

        from .person import Person
        model = Person(self._session, data['id'])
        model.data = data
        return model

    def move_to_tier(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/moveToTier".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    def replace_by_id(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/replace".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    @classmethod
    def replace_or_create(cls, session, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/replaceOrCreate"
        return session.call_api(api, attribs, 'post')

    def store_locations(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/storeLocations".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    def unlink_people(self, person_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/people/rel/{1}".format(self._id, person_id)
        return self._session.call_api(api, attribs, 'delete')

    def update_attributes(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}".format(self._id)
        data = self._session.call_api(api, attribs, 'put')

        self.data.update(attribs)
        return self

    def update_by_id_feed_items(self, feed_item_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/feedItems/{1}".format(self._id, feed_item_id)
        data = self._session.call_api(api, attribs, 'put')

        from .feed_item import FeedItem
        model = FeedItem(self._session, data['id'])
        model.data = data
        return model

    def update_by_id_locations(self, location_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/locations/{1}".format(self._id, location_id)
        data = self._session.call_api(api, attribs, 'put')

        from .location import Location
        model = Location(self._session, data['id'])
        model.data = data
        return model

    def update_by_id_management_tier_management_tiers(self, management_tier_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers/{1}".format(self._id, management_tier_id)
        data = self._session.call_api(api, attribs, 'put')

        self.data.update(attribs)
        return self

    def update_by_id_management_tiers(self, management_tier_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/managementTiers/{1}".format(self._id, management_tier_id)
        data = self._session.call_api(api, attribs, 'put')

        self.data.update(attribs)
        return self

    def update_by_id_people(self, person_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/people/{1}".format(self._id, person_id)
        data = self._session.call_api(api, attribs, 'put')

        from .person import Person
        model = Person(self._session, data['id'])
        model.data = data
        return model

    def update_by_id_permissions(self, permission_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/{0}/permissions/{1}".format(self._id, permission_id)
        data = self._session.call_api(api, attribs, 'put')

        from .permission import Permission
        model = Permission(self._session, data['id'])
        model.data = data
        return model

    @classmethod
    def upsert(cls, session, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers"
        data = session.call_api(api, attribs, 'put')

        model = ManagementTier(session, data['id'])
        model.data = data
        return model

    @classmethod
    def upsert_with_where(cls, session, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/ManagementTiers/upsertWithWhere"
        return session.call_api(api, attribs, 'post')

