# File generated by hadoop record compiler. Do not edit.
"""
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you 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.
"""
from toolazydogs.pookeeper import EXCEPTIONS
from toolazydogs.pookeeper.packets.proto.CheckVersionRequest import CheckVersionRequest
from toolazydogs.pookeeper.packets.proto.CreateRequest import CreateRequest
from toolazydogs.pookeeper.packets.proto.CreateResponse import CreateResponse
from toolazydogs.pookeeper.packets.proto.DeleteRequest import DeleteRequest
from toolazydogs.pookeeper.packets.proto.ErrorResponse import ErrorResponse
from toolazydogs.pookeeper.packets.proto.MultiHeader import MultiHeader
from toolazydogs.pookeeper.packets.proto.SetDataRequest import SetDataRequest
from toolazydogs.pookeeper.packets.proto.SetDataResponse import SetDataResponse


class TransactionResponse:
    def __init__(self, results):
        self.results = results

    def deserialize(self, input_archive, tag):
        from toolazydogs.pookeeper.zookeeper import LOGGER
        input_archive.start_record(tag)
        self.results = []
        header = MultiHeader(None, None, None)
        while not header.done:
            if header.type == CreateRequest.type:
                response = CreateResponse(None)
                response.deserialize(input_archive, tag)
                self.results.append((response.path))
            elif header.type == DeleteRequest.type:
                self.results.append(())
            elif header.type == SetDataRequest.type:
                response = SetDataResponse(None)
                response.deserialize(input_archive, tag)
                self.results.append((response.stat))
            elif header.type == CheckVersionRequest.type:
                self.results.append(())
            elif header.type == -1:
                response = ErrorResponse(None)
                response.deserialize(input_archive, tag)
                self.results.append((EXCEPTIONS[response.err]()))

            header.deserialize(input_archive, tag)

        input_archive.end_record(tag)

    def __repr__(self):
        return 'TransactionResponse(%r)' % (self.results)

    def __eq__(self, other):
        return self.results == other.results

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

    def __hash__(self):
        return hash((self.results))
