/*
 *
 *    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/OtaSoftwareUpdateRequestor/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 OtaSoftwareUpdateRequestor {
namespace Events {
namespace StateTransition {
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::kPreviousState), previousState));
  ReturnErrorOnFailure(
      DataModel::Encode(aWriter, TLV::ContextTag(Fields::kNewState), newState));
  ReturnErrorOnFailure(
      DataModel::Encode(aWriter, TLV::ContextTag(Fields::kReason), reason));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kTargetSoftwareVersion),
      targetSoftwareVersion));
  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::kPreviousState)) {
      err = DataModel::Decode(reader, previousState);
    } else if (__context_tag == to_underlying(Fields::kNewState)) {
      err = DataModel::Decode(reader, newState);
    } else if (__context_tag == to_underlying(Fields::kReason)) {
      err = DataModel::Decode(reader, reason);
    } else if (__context_tag == to_underlying(Fields::kTargetSoftwareVersion)) {
      err = DataModel::Decode(reader, targetSoftwareVersion);
    } else {
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace StateTransition.
namespace VersionApplied {
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::kSoftwareVersion), softwareVersion));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kProductID), productID));
  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::kSoftwareVersion)) {
      err = DataModel::Decode(reader, softwareVersion);
    } else if (__context_tag == to_underlying(Fields::kProductID)) {
      err = DataModel::Decode(reader, productID);
    } else {
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace VersionApplied.
namespace DownloadError {
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::kSoftwareVersion), softwareVersion));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kBytesDownloaded), bytesDownloaded));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kProgressPercent), progressPercent));
  ReturnErrorOnFailure(DataModel::Encode(
      aWriter, TLV::ContextTag(Fields::kPlatformCode), platformCode));
  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::kSoftwareVersion)) {
      err = DataModel::Decode(reader, softwareVersion);
    } else if (__context_tag == to_underlying(Fields::kBytesDownloaded)) {
      err = DataModel::Decode(reader, bytesDownloaded);
    } else if (__context_tag == to_underlying(Fields::kProgressPercent)) {
      err = DataModel::Decode(reader, progressPercent);
    } else if (__context_tag == to_underlying(Fields::kPlatformCode)) {
      err = DataModel::Decode(reader, platformCode);
    } else {
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace DownloadError.
} // namespace Events
} // namespace OtaSoftwareUpdateRequestor
} // namespace Clusters
} // namespace app
} // namespace chip
