# Leviton Cloud Services API model Organization.
# 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 Organization(BaseModel):
    def __init__(self, session, model_id=None):
        super(Organization, self).__init__(session, model_id)

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

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

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

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

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

    def count_locations(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/locations/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 = "/Organizations/{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 = "/Organizations/{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 = "/Organizations/{0}/permissions/count".format(self._id)
        return self._session.call_api(api, attribs, 'get')

    def count_schedules(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/schedules/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 = "/Organizations"
        return session.call_api(api, attribs, 'post')

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

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

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

    def create_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{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 = "/Organizations"
        return session.call_api(api, attribs, 'post')

    def create_people(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{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 = "/Organizations/{0}/permissions".format(self._id)
        return self._session.call_api(api, attribs, 'post')

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

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

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

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

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

    def delete_management_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{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 = "/Organizations/{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 = "/Organizations/{0}/permissions".format(self._id)
        return self._session.call_api(api, attribs, 'delete')

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

    def destroy_by_id_holidays(self, holiday_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/holidays/{1}".format(self._id, holiday_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_invitations(self, invitation_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/invitations/{1}".format(self._id, invitation_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 = "/Organizations/{0}/locations/{1}".format(self._id, location_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 = "/Organizations/{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 = "/Organizations/{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 = "/Organizations/{0}/permissions/{1}".format(self._id, permission_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_schedules(self, schedule_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/schedules/{1}".format(self._id, schedule_id)
        return self._session.call_api(api, attribs, 'delete')

    def exists(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{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 = "/Organizations/{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 = "/Organizations"
        items = session.call_api(api, attribs, 'get')

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

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

        self.data.update(data)
        return self

    def find_by_id_holidays(self, holiday_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/holidays/{1}".format(self._id, holiday_id)
        return self._session.call_api(api, attribs, 'get')

    def find_by_id_invitations(self, invitation_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/invitations/{1}".format(self._id, invitation_id)
        data = self._session.call_api(api, attribs, 'get')

        from .invitation import Invitation
        model = Invitation(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 = "/Organizations/{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_tiers(self, management_tier_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/managementTiers/{1}".format(self._id, management_tier_id)
        data = self._session.call_api(api, attribs, 'get')

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

    def find_by_id_people(self, person_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{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 = "/Organizations/{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

    def find_by_id_schedules(self, schedule_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/schedules/{1}".format(self._id, schedule_id)
        return self._session.call_api(api, attribs, 'get')

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

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

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

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

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

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

    def get_locations(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{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_tiers(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/managementTiers".format(self._id)
        items = self._session.call_api(api, attribs, 'get')

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

    def get_people(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{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 = "/Organizations/{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 get_schedules(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/schedules".format(self._id)
        return self._session.call_api(api, attribs, 'get')

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

    def link_people(self, person_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{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 remove_person(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/removePerson".format(self._id)
        return self._session.call_api(api, attribs, 'post')

    def replace_by_id(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{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 = "/Organizations/replaceOrCreate"
        return session.call_api(api, attribs, 'post')

    def subscribe_to_plan(self, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/subscribeToPlan".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 = "/Organizations/{0}/people/rel/{1}".format(self._id, person_id)
        return self._session.call_api(api, attribs, 'delete')

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

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

        self.data.update(attribs)
        return self

    def update_by_id_holidays(self, holiday_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/holidays/{1}".format(self._id, holiday_id)
        return self._session.call_api(api, attribs, 'put')

    def update_by_id_invitations(self, invitation_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/invitations/{1}".format(self._id, invitation_id)
        data = self._session.call_api(api, attribs, 'put')

        from .invitation import Invitation
        model = Invitation(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 = "/Organizations/{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_tiers(self, management_tier_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/managementTiers/{1}".format(self._id, management_tier_id)
        data = self._session.call_api(api, attribs, 'put')

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

    def update_by_id_people(self, person_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{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 = "/Organizations/{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

    def update_by_id_schedules(self, schedule_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Organizations/{0}/schedules/{1}".format(self._id, schedule_id)
        return self._session.call_api(api, attribs, 'put')

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

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

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

