/*
 *
 *    Copyright (c) 2022 Project CHIP Authors
 *
 *    Licensed 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.
 */

// THIS FILE IS GENERATED BY ZAP
// This file is generated from clusters-Events.ipp.zapt

#include <clusters/DoorLock/Events.h>

#include <app/data-model/Decode.h>
#include <app/data-model/Encode.h>
#include <app/data-model/StructDecodeIterator.h>
#include <app/data-model/WrappedStructEncoder.h>

namespace chip {
namespace app {
namespace Clusters {
namespace DoorLock {
namespace Events {
namespace DoorLockAlarm {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  TLV::TLVType outer;
  ReturnErrorOnFailure(
      aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kAlarmCode), alarmCode));
  return aWriter.EndContainer(outer);
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
  detail::StructDecodeIterator __iterator(reader);
  while (true) {
    uint8_t __context_tag = 0;
    CHIP_ERROR err = __iterator.Next(__context_tag);
    VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
    ReturnErrorOnFailure(err);

    if (__context_tag == to_underlying(Fields::kAlarmCode)) {
      err = DataModel::Decode(reader, alarmCode);
    } else {
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace DoorLockAlarm.
namespace DoorStateChange {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  TLV::TLVType outer;
  ReturnErrorOnFailure(
      aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kDoorState), doorState));
  return aWriter.EndContainer(outer);
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
  detail::StructDecodeIterator __iterator(reader);
  while (true) {
    uint8_t __context_tag = 0;
    CHIP_ERROR err = __iterator.Next(__context_tag);
    VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
    ReturnErrorOnFailure(err);

    if (__context_tag == to_underlying(Fields::kDoorState)) {
      err = DataModel::Decode(reader, doorState);
    } else {
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace DoorStateChange.
namespace LockOperation {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  TLV::TLVType outer;
  ReturnErrorOnFailure(
      aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kLockOperationType), lockOperationType));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kOperationSource), operationSource));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kSourceNode), sourceNode));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kCredentials), credentials));
  return aWriter.EndContainer(outer);
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
  detail::StructDecodeIterator __iterator(reader);
  while (true) {
    uint8_t __context_tag = 0;
    CHIP_ERROR err = __iterator.Next(__context_tag);
    VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
    ReturnErrorOnFailure(err);

    if (__context_tag == to_underlying(Fields::kLockOperationType)) {
      err = DataModel::Decode(reader, lockOperationType);
    } else if (__context_tag == to_underlying(Fields::kOperationSource)) {
      err = DataModel::Decode(reader, operationSource);
    } else if (__context_tag == to_underlying(Fields::kUserIndex)) {
      err = DataModel::Decode(reader, userIndex);
    } else if (__context_tag == to_underlying(Fields::kFabricIndex)) {
      err = DataModel::Decode(reader, fabricIndex);
    } else if (__context_tag == to_underlying(Fields::kSourceNode)) {
      err = DataModel::Decode(reader, sourceNode);
    } else if (__context_tag == to_underlying(Fields::kCredentials)) {
      err = DataModel::Decode(reader, credentials);
    } else {
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace LockOperation.
namespace LockOperationError {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  TLV::TLVType outer;
  ReturnErrorOnFailure(
      aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kLockOperationType), lockOperationType));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kOperationSource), operationSource));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kOperationError), operationError));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kSourceNode), sourceNode));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kCredentials), credentials));
  return aWriter.EndContainer(outer);
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
  detail::StructDecodeIterator __iterator(reader);
  while (true) {
    uint8_t __context_tag = 0;
    CHIP_ERROR err = __iterator.Next(__context_tag);
    VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
    ReturnErrorOnFailure(err);

    if (__context_tag == to_underlying(Fields::kLockOperationType)) {
      err = DataModel::Decode(reader, lockOperationType);
    } else if (__context_tag == to_underlying(Fields::kOperationSource)) {
      err = DataModel::Decode(reader, operationSource);
    } else if (__context_tag == to_underlying(Fields::kOperationError)) {
      err = DataModel::Decode(reader, operationError);
    } else if (__context_tag == to_underlying(Fields::kUserIndex)) {
      err = DataModel::Decode(reader, userIndex);
    } else if (__context_tag == to_underlying(Fields::kFabricIndex)) {
      err = DataModel::Decode(reader, fabricIndex);
    } else if (__context_tag == to_underlying(Fields::kSourceNode)) {
      err = DataModel::Decode(reader, sourceNode);
    } else if (__context_tag == to_underlying(Fields::kCredentials)) {
      err = DataModel::Decode(reader, credentials);
    } else {
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace LockOperationError.
namespace LockUserChange {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  TLV::TLVType outer;
  ReturnErrorOnFailure(
      aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kLockDataType), lockDataType));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kDataOperationType), dataOperationType));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kOperationSource), operationSource));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kUserIndex), userIndex));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kFabricIndex), fabricIndex));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kSourceNode), sourceNode));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kDataIndex), dataIndex));
  return aWriter.EndContainer(outer);
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
  detail::StructDecodeIterator __iterator(reader);
  while (true) {
    uint8_t __context_tag = 0;
    CHIP_ERROR err = __iterator.Next(__context_tag);
    VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
    ReturnErrorOnFailure(err);

    if (__context_tag == to_underlying(Fields::kLockDataType)) {
      err = DataModel::Decode(reader, lockDataType);
    } else if (__context_tag == to_underlying(Fields::kDataOperationType)) {
      err = DataModel::Decode(reader, dataOperationType);
    } else if (__context_tag == to_underlying(Fields::kOperationSource)) {
      err = DataModel::Decode(reader, operationSource);
    } else if (__context_tag == to_underlying(Fields::kUserIndex)) {
      err = DataModel::Decode(reader, userIndex);
    } else if (__context_tag == to_underlying(Fields::kFabricIndex)) {
      err = DataModel::Decode(reader, fabricIndex);
    } else if (__context_tag == to_underlying(Fields::kSourceNode)) {
      err = DataModel::Decode(reader, sourceNode);
    } else if (__context_tag == to_underlying(Fields::kDataIndex)) {
      err = DataModel::Decode(reader, dataIndex);
    } else {
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace LockUserChange.
} // namespace Events
} // namespace DoorLock
} // namespace Clusters
} // namespace app
} // namespace chip
