/*
 *
 *    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/DeviceEnergyManagement/Structs.h>

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

namespace chip {
namespace app {
namespace Clusters {
namespace DeviceEnergyManagement {
namespace Structs {

namespace CostStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kCostType), costType);
  encoder.Encode(to_underlying(Fields::kValue), value);
  encoder.Encode(to_underlying(Fields::kDecimalPoints), decimalPoints);
  encoder.Encode(to_underlying(Fields::kCurrency), currency);
  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::kCostType)) {
      err = DataModel::Decode(reader, costType);
    } else if (__context_tag == to_underlying(Fields::kValue)) {
      err = DataModel::Decode(reader, value);
    } else if (__context_tag == to_underlying(Fields::kDecimalPoints)) {
      err = DataModel::Decode(reader, decimalPoints);
    } else if (__context_tag == to_underlying(Fields::kCurrency)) {
      err = DataModel::Decode(reader, currency);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace CostStruct

namespace PowerAdjustStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kMinPower), minPower);
  encoder.Encode(to_underlying(Fields::kMaxPower), maxPower);
  encoder.Encode(to_underlying(Fields::kMinDuration), minDuration);
  encoder.Encode(to_underlying(Fields::kMaxDuration), maxDuration);
  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::kMinPower)) {
      err = DataModel::Decode(reader, minPower);
    } else if (__context_tag == to_underlying(Fields::kMaxPower)) {
      err = DataModel::Decode(reader, maxPower);
    } else if (__context_tag == to_underlying(Fields::kMinDuration)) {
      err = DataModel::Decode(reader, minDuration);
    } else if (__context_tag == to_underlying(Fields::kMaxDuration)) {
      err = DataModel::Decode(reader, maxDuration);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace PowerAdjustStruct

namespace PowerAdjustCapabilityStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kPowerAdjustCapability),
                 powerAdjustCapability);
  encoder.Encode(to_underlying(Fields::kCause), cause);
  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::kPowerAdjustCapability)) {
      err = DataModel::Decode(reader, powerAdjustCapability);
    } else if (__context_tag == to_underlying(Fields::kCause)) {
      err = DataModel::Decode(reader, cause);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace PowerAdjustCapabilityStruct

namespace SlotStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kMinDuration), minDuration);
  encoder.Encode(to_underlying(Fields::kMaxDuration), maxDuration);
  encoder.Encode(to_underlying(Fields::kDefaultDuration), defaultDuration);
  encoder.Encode(to_underlying(Fields::kElapsedSlotTime), elapsedSlotTime);
  encoder.Encode(to_underlying(Fields::kRemainingSlotTime), remainingSlotTime);
  encoder.Encode(to_underlying(Fields::kSlotIsPausable), slotIsPausable);
  encoder.Encode(to_underlying(Fields::kMinPauseDuration), minPauseDuration);
  encoder.Encode(to_underlying(Fields::kMaxPauseDuration), maxPauseDuration);
  encoder.Encode(to_underlying(Fields::kManufacturerESAState),
                 manufacturerESAState);
  encoder.Encode(to_underlying(Fields::kNominalPower), nominalPower);
  encoder.Encode(to_underlying(Fields::kMinPower), minPower);
  encoder.Encode(to_underlying(Fields::kMaxPower), maxPower);
  encoder.Encode(to_underlying(Fields::kNominalEnergy), nominalEnergy);
  encoder.Encode(to_underlying(Fields::kCosts), costs);
  encoder.Encode(to_underlying(Fields::kMinPowerAdjustment),
                 minPowerAdjustment);
  encoder.Encode(to_underlying(Fields::kMaxPowerAdjustment),
                 maxPowerAdjustment);
  encoder.Encode(to_underlying(Fields::kMinDurationAdjustment),
                 minDurationAdjustment);
  encoder.Encode(to_underlying(Fields::kMaxDurationAdjustment),
                 maxDurationAdjustment);
  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::kMinDuration)) {
      err = DataModel::Decode(reader, minDuration);
    } else if (__context_tag == to_underlying(Fields::kMaxDuration)) {
      err = DataModel::Decode(reader, maxDuration);
    } else if (__context_tag == to_underlying(Fields::kDefaultDuration)) {
      err = DataModel::Decode(reader, defaultDuration);
    } else if (__context_tag == to_underlying(Fields::kElapsedSlotTime)) {
      err = DataModel::Decode(reader, elapsedSlotTime);
    } else if (__context_tag == to_underlying(Fields::kRemainingSlotTime)) {
      err = DataModel::Decode(reader, remainingSlotTime);
    } else if (__context_tag == to_underlying(Fields::kSlotIsPausable)) {
      err = DataModel::Decode(reader, slotIsPausable);
    } else if (__context_tag == to_underlying(Fields::kMinPauseDuration)) {
      err = DataModel::Decode(reader, minPauseDuration);
    } else if (__context_tag == to_underlying(Fields::kMaxPauseDuration)) {
      err = DataModel::Decode(reader, maxPauseDuration);
    } else if (__context_tag == to_underlying(Fields::kManufacturerESAState)) {
      err = DataModel::Decode(reader, manufacturerESAState);
    } else if (__context_tag == to_underlying(Fields::kNominalPower)) {
      err = DataModel::Decode(reader, nominalPower);
    } else if (__context_tag == to_underlying(Fields::kMinPower)) {
      err = DataModel::Decode(reader, minPower);
    } else if (__context_tag == to_underlying(Fields::kMaxPower)) {
      err = DataModel::Decode(reader, maxPower);
    } else if (__context_tag == to_underlying(Fields::kNominalEnergy)) {
      err = DataModel::Decode(reader, nominalEnergy);
    } else if (__context_tag == to_underlying(Fields::kCosts)) {
      err = DataModel::Decode(reader, costs);
    } else if (__context_tag == to_underlying(Fields::kMinPowerAdjustment)) {
      err = DataModel::Decode(reader, minPowerAdjustment);
    } else if (__context_tag == to_underlying(Fields::kMaxPowerAdjustment)) {
      err = DataModel::Decode(reader, maxPowerAdjustment);
    } else if (__context_tag == to_underlying(Fields::kMinDurationAdjustment)) {
      err = DataModel::Decode(reader, minDurationAdjustment);
    } else if (__context_tag == to_underlying(Fields::kMaxDurationAdjustment)) {
      err = DataModel::Decode(reader, maxDurationAdjustment);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace SlotStruct

namespace ForecastStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kForecastID), forecastID);
  encoder.Encode(to_underlying(Fields::kActiveSlotNumber), activeSlotNumber);
  encoder.Encode(to_underlying(Fields::kStartTime), startTime);
  encoder.Encode(to_underlying(Fields::kEndTime), endTime);
  encoder.Encode(to_underlying(Fields::kEarliestStartTime), earliestStartTime);
  encoder.Encode(to_underlying(Fields::kLatestEndTime), latestEndTime);
  encoder.Encode(to_underlying(Fields::kIsPausable), isPausable);
  encoder.Encode(to_underlying(Fields::kSlots), slots);
  encoder.Encode(to_underlying(Fields::kForecastUpdateReason),
                 forecastUpdateReason);
  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::kForecastID)) {
      err = DataModel::Decode(reader, forecastID);
    } else if (__context_tag == to_underlying(Fields::kActiveSlotNumber)) {
      err = DataModel::Decode(reader, activeSlotNumber);
    } else if (__context_tag == to_underlying(Fields::kStartTime)) {
      err = DataModel::Decode(reader, startTime);
    } else if (__context_tag == to_underlying(Fields::kEndTime)) {
      err = DataModel::Decode(reader, endTime);
    } else if (__context_tag == to_underlying(Fields::kEarliestStartTime)) {
      err = DataModel::Decode(reader, earliestStartTime);
    } else if (__context_tag == to_underlying(Fields::kLatestEndTime)) {
      err = DataModel::Decode(reader, latestEndTime);
    } else if (__context_tag == to_underlying(Fields::kIsPausable)) {
      err = DataModel::Decode(reader, isPausable);
    } else if (__context_tag == to_underlying(Fields::kSlots)) {
      err = DataModel::Decode(reader, slots);
    } else if (__context_tag == to_underlying(Fields::kForecastUpdateReason)) {
      err = DataModel::Decode(reader, forecastUpdateReason);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace ForecastStruct

namespace ConstraintsStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kStartTime), startTime);
  encoder.Encode(to_underlying(Fields::kDuration), duration);
  encoder.Encode(to_underlying(Fields::kNominalPower), nominalPower);
  encoder.Encode(to_underlying(Fields::kMaximumEnergy), maximumEnergy);
  encoder.Encode(to_underlying(Fields::kLoadControl), loadControl);
  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::kStartTime)) {
      err = DataModel::Decode(reader, startTime);
    } else if (__context_tag == to_underlying(Fields::kDuration)) {
      err = DataModel::Decode(reader, duration);
    } else if (__context_tag == to_underlying(Fields::kNominalPower)) {
      err = DataModel::Decode(reader, nominalPower);
    } else if (__context_tag == to_underlying(Fields::kMaximumEnergy)) {
      err = DataModel::Decode(reader, maximumEnergy);
    } else if (__context_tag == to_underlying(Fields::kLoadControl)) {
      err = DataModel::Decode(reader, loadControl);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace ConstraintsStruct

namespace SlotAdjustmentStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kSlotIndex), slotIndex);
  encoder.Encode(to_underlying(Fields::kNominalPower), nominalPower);
  encoder.Encode(to_underlying(Fields::kDuration), duration);
  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::kSlotIndex)) {
      err = DataModel::Decode(reader, slotIndex);
    } else if (__context_tag == to_underlying(Fields::kNominalPower)) {
      err = DataModel::Decode(reader, nominalPower);
    } else if (__context_tag == to_underlying(Fields::kDuration)) {
      err = DataModel::Decode(reader, duration);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace SlotAdjustmentStruct
} // namespace Structs
} // namespace DeviceEnergyManagement
} // namespace Clusters
} // namespace app
} // namespace chip
