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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    def destroy_by_id_load_definitions(self, load_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/loadDefinitions/{1}".format(self._id, load_definition_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_sensor_definitions(self, sensor_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/sensorDefinitions/{1}".format(self._id, sensor_definition_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_shade_definitions(self, shade_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/shadeDefinitions/{1}".format(self._id, shade_definition_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_thermostat_definitions(self, thermostat_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/thermostatDefinitions/{1}".format(self._id, thermostat_definition_id)
        return self._session.call_api(api, attribs, 'delete')

    def destroy_by_id_touchscreen_definitions(self, touchscreen_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/touchscreenDefinitions/{1}".format(self._id, touchscreen_definition_id)
        return self._session.call_api(api, attribs, 'delete')

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

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

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

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

        self.data.update(data)
        return self

    def find_by_id_load_definitions(self, load_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/loadDefinitions/{1}".format(self._id, load_definition_id)
        data = self._session.call_api(api, attribs, 'get')

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

    def find_by_id_sensor_definitions(self, sensor_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/sensorDefinitions/{1}".format(self._id, sensor_definition_id)
        data = self._session.call_api(api, attribs, 'get')

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

    def find_by_id_shade_definitions(self, shade_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/shadeDefinitions/{1}".format(self._id, shade_definition_id)
        data = self._session.call_api(api, attribs, 'get')

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

    def find_by_id_thermostat_definitions(self, thermostat_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/thermostatDefinitions/{1}".format(self._id, thermostat_definition_id)
        data = self._session.call_api(api, attribs, 'get')

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

    def find_by_id_touchscreen_definitions(self, touchscreen_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/touchscreenDefinitions/{1}".format(self._id, touchscreen_definition_id)
        data = self._session.call_api(api, attribs, 'get')

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        self.data.update(attribs)
        return self

    def update_by_id_load_definitions(self, load_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/loadDefinitions/{1}".format(self._id, load_definition_id)
        data = self._session.call_api(api, attribs, 'put')

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

    def update_by_id_sensor_definitions(self, sensor_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/sensorDefinitions/{1}".format(self._id, sensor_definition_id)
        data = self._session.call_api(api, attribs, 'put')

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

    def update_by_id_shade_definitions(self, shade_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/shadeDefinitions/{1}".format(self._id, shade_definition_id)
        data = self._session.call_api(api, attribs, 'put')

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

    def update_by_id_thermostat_definitions(self, thermostat_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/thermostatDefinitions/{1}".format(self._id, thermostat_definition_id)
        data = self._session.call_api(api, attribs, 'put')

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

    def update_by_id_touchscreen_definitions(self, touchscreen_definition_id, attribs=None):
        if attribs is None:
            attribs = {}
        api = "/Whitelist/{0}/touchscreenDefinitions/{1}".format(self._id, touchscreen_definition_id)
        data = self._session.call_api(api, attribs, 'put')

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

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

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

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

