/*
 *
 *    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-Commands.ipp.zapt

#include <clusters/GeneralCommissioning/Commands.h>

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

namespace chip {
namespace app {
namespace Clusters {
namespace GeneralCommissioning {
namespace Commands {
namespace ArmFailSafe {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kExpiryLengthSeconds),
                 expiryLengthSeconds);
  encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb);
  return encoder.Finalize();
}

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::kExpiryLengthSeconds)) {
      err = DataModel::Decode(reader, expiryLengthSeconds);
    } else if (__context_tag == to_underlying(Fields::kBreadcrumb)) {
      err = DataModel::Decode(reader, breadcrumb);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace ArmFailSafe.
namespace ArmFailSafeResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter &aWriter,
                        TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kErrorCode), errorCode);
  encoder.Encode(to_underlying(Fields::kDebugText), debugText);
  return encoder.Finalize();
}

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::kErrorCode)) {
      err = DataModel::Decode(reader, errorCode);
    } else if (__context_tag == to_underlying(Fields::kDebugText)) {
      err = DataModel::Decode(reader, debugText);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace ArmFailSafeResponse.
namespace SetRegulatoryConfig {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kNewRegulatoryConfig),
                 newRegulatoryConfig);
  encoder.Encode(to_underlying(Fields::kCountryCode), countryCode);
  encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb);
  return encoder.Finalize();
}

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::kNewRegulatoryConfig)) {
      err = DataModel::Decode(reader, newRegulatoryConfig);
    } else if (__context_tag == to_underlying(Fields::kCountryCode)) {
      err = DataModel::Decode(reader, countryCode);
    } else if (__context_tag == to_underlying(Fields::kBreadcrumb)) {
      err = DataModel::Decode(reader, breadcrumb);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace SetRegulatoryConfig.
namespace SetRegulatoryConfigResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter &aWriter,
                        TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kErrorCode), errorCode);
  encoder.Encode(to_underlying(Fields::kDebugText), debugText);
  return encoder.Finalize();
}

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::kErrorCode)) {
      err = DataModel::Decode(reader, errorCode);
    } else if (__context_tag == to_underlying(Fields::kDebugText)) {
      err = DataModel::Decode(reader, debugText);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace SetRegulatoryConfigResponse.
namespace CommissioningComplete {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader,
                                 FabricIndex aAccessingFabricIndex) {
  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);

    ReturnErrorOnFailure(err);
  }
}
} // namespace CommissioningComplete.
namespace CommissioningCompleteResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter &aWriter,
                        TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kErrorCode), errorCode);
  encoder.Encode(to_underlying(Fields::kDebugText), debugText);
  return encoder.Finalize();
}

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::kErrorCode)) {
      err = DataModel::Decode(reader, errorCode);
    } else if (__context_tag == to_underlying(Fields::kDebugText)) {
      err = DataModel::Decode(reader, debugText);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace CommissioningCompleteResponse.
namespace SetTCAcknowledgements {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kTCVersion), TCVersion);
  encoder.Encode(to_underlying(Fields::kTCUserResponse), TCUserResponse);
  return encoder.Finalize();
}

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::kTCVersion)) {
      err = DataModel::Decode(reader, TCVersion);
    } else if (__context_tag == to_underlying(Fields::kTCUserResponse)) {
      err = DataModel::Decode(reader, TCUserResponse);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace SetTCAcknowledgements.
namespace SetTCAcknowledgementsResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter &aWriter,
                        TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kErrorCode), errorCode);
  return encoder.Finalize();
}

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::kErrorCode)) {
      err = DataModel::Decode(reader, errorCode);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace SetTCAcknowledgementsResponse.
} // namespace Commands
} // namespace GeneralCommissioning
} // namespace Clusters
} // namespace app
} // namespace chip
