/*
 *
 *    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/DeviceEnergyManagement/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 DeviceEnergyManagement {
namespace Commands {
namespace PowerAdjustRequest {

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

    ReturnErrorOnFailure(err);
  }
}
} // namespace PowerAdjustRequest.
namespace CancelPowerAdjustRequest {

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) {
  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 CancelPowerAdjustRequest.
namespace StartTimeAdjustRequest {

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

    ReturnErrorOnFailure(err);
  }
}
} // namespace StartTimeAdjustRequest.
namespace PauseRequest {

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

    ReturnErrorOnFailure(err);
  }
}
} // namespace PauseRequest.
namespace ResumeRequest {

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) {
  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 ResumeRequest.
namespace ModifyForecastRequest {

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::kSlotAdjustments), slotAdjustments);
  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::kForecastID)) {
      err = DataModel::Decode(reader, forecastID);
    } else if (__context_tag == to_underlying(Fields::kSlotAdjustments)) {
      err = DataModel::Decode(reader, slotAdjustments);
    } else if (__context_tag == to_underlying(Fields::kCause)) {
      err = DataModel::Decode(reader, cause);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace ModifyForecastRequest.
namespace RequestConstraintBasedForecast {

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

    ReturnErrorOnFailure(err);
  }
}
} // namespace RequestConstraintBasedForecast.
namespace CancelRequest {

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) {
  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 CancelRequest.
} // namespace Commands
} // namespace DeviceEnergyManagement
} // namespace Clusters
} // namespace app
} // namespace chip
