# Path: thingsboard_gateway/connectors/converter.py
# class Converter(ABC):
#     def convert(self, config, data):


from thingsboard_gateway.connectors.converter import Converter, log
from thingsboard_gateway.gateway.proto.messages_pb2 import ConnectMsg, DisconnectMsg, GatewayAttributesMsg, GatewayAttributesRequestMsg, GatewayClaimMsg, \
    GatewayRpcResponseMsg, GatewayTelemetryMsg, KeyValueProto, KeyValueType, Response
#      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.



class GrpcUplinkConverter(Converter):
    def __init__(self):
        self.__conversion_methods = {
            Response.DESCRIPTOR: self.__convert_response_msg,
            GatewayTelemetryMsg.DESCRIPTOR: self.__convert_gateway_telemetry_msg,
            GatewayAttributesMsg.DESCRIPTOR: self.__convert_gateway_attributes_msg,
            GatewayClaimMsg.DESCRIPTOR: self.__convert_gateway_claim_msg,
            ConnectMsg.DESCRIPTOR: self.__convert_connect_msg,
            DisconnectMsg.DESCRIPTOR: self.__convert_disconnect_msg,
            GatewayRpcResponseMsg.DESCRIPTOR: self.__convert_gateway_rpc_response_msg,
            GatewayAttributesRequestMsg.DESCRIPTOR: self.__convert_gateway_attributes_request_msg
            }

    def convert(self, config, data):
        try:
            if self.__conversion_methods.get(data.DESCRIPTOR) is not None:
                return self.__conversion_methods[data.DESCRIPTOR](data)
            else:

# Path: thingsboard_gateway/connectors/converter.py
# class Converter(ABC):
#     def convert(self, config, data):


# Path: thingsboard_gateway/gateway/grpc_service/grpc_uplink_converter.py
from thingsboard_gateway.connectors.converter import Converter, log
from thingsboard_gateway.gateway.proto.messages_pb2 import ConnectMsg, DisconnectMsg, GatewayAttributesMsg, GatewayAttributesRequestMsg, GatewayClaimMsg, \
    GatewayRpcResponseMsg, GatewayTelemetryMsg, KeyValueProto, KeyValueType, Response

#      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.



class GrpcUplinkConverter(Converter):
    def __init__(self):
        self.__conversion_methods = {
            Response.DESCRIPTOR: self.__convert_response_msg,
            GatewayTelemetryMsg.DESCRIPTOR: self.__convert_gateway_telemetry_msg,
            GatewayAttributesMsg.DESCRIPTOR: self.__convert_gateway_attributes_msg,
            GatewayClaimMsg.DESCRIPTOR: self.__convert_gateway_claim_msg,
            ConnectMsg.DESCRIPTOR: self.__convert_connect_msg,
            DisconnectMsg.DESCRIPTOR: self.__convert_disconnect_msg,
            GatewayRpcResponseMsg.DESCRIPTOR: self.__convert_gateway_rpc_response_msg,
            GatewayAttributesRequestMsg.DESCRIPTOR: self.__convert_gateway_attributes_request_msg
            }

    def convert(self, config, data):
        try:
            if self.__conversion_methods.get(data.DESCRIPTOR) is not None:
                return self.__conversion_methods[data.DESCRIPTOR](data)
            else:

                log.error("[GRPC] unknown uplink message descriptor: %r", data.DESCRIPTOR)