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

#include <clusters/NetworkCommissioning/Structs.h>

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

namespace chip {
namespace app {
namespace Clusters {
namespace NetworkCommissioning {
namespace Structs {

namespace NetworkInfoStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kNetworkID), networkID);
  encoder.Encode(to_underlying(Fields::kConnected), connected);
  encoder.Encode(to_underlying(Fields::kNetworkIdentifier), networkIdentifier);
  encoder.Encode(to_underlying(Fields::kClientIdentifier), clientIdentifier);
  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::kNetworkID)) {
      err = DataModel::Decode(reader, networkID);
    } else if (__context_tag == to_underlying(Fields::kConnected)) {
      err = DataModel::Decode(reader, connected);
    } else if (__context_tag == to_underlying(Fields::kNetworkIdentifier)) {
      err = DataModel::Decode(reader, networkIdentifier);
    } else if (__context_tag == to_underlying(Fields::kClientIdentifier)) {
      err = DataModel::Decode(reader, clientIdentifier);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace NetworkInfoStruct

namespace ThreadInterfaceScanResultStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kPanId), panId);
  encoder.Encode(to_underlying(Fields::kExtendedPanId), extendedPanId);
  encoder.Encode(to_underlying(Fields::kNetworkName), networkName);
  encoder.Encode(to_underlying(Fields::kChannel), channel);
  encoder.Encode(to_underlying(Fields::kVersion), version);
  encoder.Encode(to_underlying(Fields::kExtendedAddress), extendedAddress);
  encoder.Encode(to_underlying(Fields::kRssi), rssi);
  encoder.Encode(to_underlying(Fields::kLqi), lqi);
  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::kPanId)) {
      err = DataModel::Decode(reader, panId);
    } else if (__context_tag == to_underlying(Fields::kExtendedPanId)) {
      err = DataModel::Decode(reader, extendedPanId);
    } else if (__context_tag == to_underlying(Fields::kNetworkName)) {
      err = DataModel::Decode(reader, networkName);
    } else if (__context_tag == to_underlying(Fields::kChannel)) {
      err = DataModel::Decode(reader, channel);
    } else if (__context_tag == to_underlying(Fields::kVersion)) {
      err = DataModel::Decode(reader, version);
    } else if (__context_tag == to_underlying(Fields::kExtendedAddress)) {
      err = DataModel::Decode(reader, extendedAddress);
    } else if (__context_tag == to_underlying(Fields::kRssi)) {
      err = DataModel::Decode(reader, rssi);
    } else if (__context_tag == to_underlying(Fields::kLqi)) {
      err = DataModel::Decode(reader, lqi);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace ThreadInterfaceScanResultStruct

namespace WiFiInterfaceScanResultStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kSecurity), security);
  encoder.Encode(to_underlying(Fields::kSsid), ssid);
  encoder.Encode(to_underlying(Fields::kBssid), bssid);
  encoder.Encode(to_underlying(Fields::kChannel), channel);
  encoder.Encode(to_underlying(Fields::kWiFiBand), wiFiBand);
  encoder.Encode(to_underlying(Fields::kRssi), rssi);
  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::kSecurity)) {
      err = DataModel::Decode(reader, security);
    } else if (__context_tag == to_underlying(Fields::kSsid)) {
      err = DataModel::Decode(reader, ssid);
    } else if (__context_tag == to_underlying(Fields::kBssid)) {
      err = DataModel::Decode(reader, bssid);
    } else if (__context_tag == to_underlying(Fields::kChannel)) {
      err = DataModel::Decode(reader, channel);
    } else if (__context_tag == to_underlying(Fields::kWiFiBand)) {
      err = DataModel::Decode(reader, wiFiBand);
    } else if (__context_tag == to_underlying(Fields::kRssi)) {
      err = DataModel::Decode(reader, rssi);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace WiFiInterfaceScanResultStruct
} // namespace Structs
} // namespace NetworkCommissioning
} // namespace Clusters
} // namespace app
} // namespace chip
