/*
 *
 *    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/LevelControl/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 LevelControl {
namespace Commands {
namespace MoveToLevel {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kLevel), level);
  encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime);
  encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask);
  encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride);
  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::kLevel)) {
      err = DataModel::Decode(reader, level);
    } else if (__context_tag == to_underlying(Fields::kTransitionTime)) {
      err = DataModel::Decode(reader, transitionTime);
    } else if (__context_tag == to_underlying(Fields::kOptionsMask)) {
      err = DataModel::Decode(reader, optionsMask);
    } else if (__context_tag == to_underlying(Fields::kOptionsOverride)) {
      err = DataModel::Decode(reader, optionsOverride);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace MoveToLevel.
namespace Move {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kMoveMode), moveMode);
  encoder.Encode(to_underlying(Fields::kRate), rate);
  encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask);
  encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride);
  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::kMoveMode)) {
      err = DataModel::Decode(reader, moveMode);
    } else if (__context_tag == to_underlying(Fields::kRate)) {
      err = DataModel::Decode(reader, rate);
    } else if (__context_tag == to_underlying(Fields::kOptionsMask)) {
      err = DataModel::Decode(reader, optionsMask);
    } else if (__context_tag == to_underlying(Fields::kOptionsOverride)) {
      err = DataModel::Decode(reader, optionsOverride);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace Move.
namespace Step {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kStepMode), stepMode);
  encoder.Encode(to_underlying(Fields::kStepSize), stepSize);
  encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime);
  encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask);
  encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride);
  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::kStepMode)) {
      err = DataModel::Decode(reader, stepMode);
    } else if (__context_tag == to_underlying(Fields::kStepSize)) {
      err = DataModel::Decode(reader, stepSize);
    } else if (__context_tag == to_underlying(Fields::kTransitionTime)) {
      err = DataModel::Decode(reader, transitionTime);
    } else if (__context_tag == to_underlying(Fields::kOptionsMask)) {
      err = DataModel::Decode(reader, optionsMask);
    } else if (__context_tag == to_underlying(Fields::kOptionsOverride)) {
      err = DataModel::Decode(reader, optionsOverride);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace Step.
namespace Stop {

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

    ReturnErrorOnFailure(err);
  }
}
} // namespace Stop.
namespace MoveToLevelWithOnOff {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kLevel), level);
  encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime);
  encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask);
  encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride);
  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::kLevel)) {
      err = DataModel::Decode(reader, level);
    } else if (__context_tag == to_underlying(Fields::kTransitionTime)) {
      err = DataModel::Decode(reader, transitionTime);
    } else if (__context_tag == to_underlying(Fields::kOptionsMask)) {
      err = DataModel::Decode(reader, optionsMask);
    } else if (__context_tag == to_underlying(Fields::kOptionsOverride)) {
      err = DataModel::Decode(reader, optionsOverride);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace MoveToLevelWithOnOff.
namespace MoveWithOnOff {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kMoveMode), moveMode);
  encoder.Encode(to_underlying(Fields::kRate), rate);
  encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask);
  encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride);
  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::kMoveMode)) {
      err = DataModel::Decode(reader, moveMode);
    } else if (__context_tag == to_underlying(Fields::kRate)) {
      err = DataModel::Decode(reader, rate);
    } else if (__context_tag == to_underlying(Fields::kOptionsMask)) {
      err = DataModel::Decode(reader, optionsMask);
    } else if (__context_tag == to_underlying(Fields::kOptionsOverride)) {
      err = DataModel::Decode(reader, optionsOverride);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace MoveWithOnOff.
namespace StepWithOnOff {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kStepMode), stepMode);
  encoder.Encode(to_underlying(Fields::kStepSize), stepSize);
  encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime);
  encoder.Encode(to_underlying(Fields::kOptionsMask), optionsMask);
  encoder.Encode(to_underlying(Fields::kOptionsOverride), optionsOverride);
  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::kStepMode)) {
      err = DataModel::Decode(reader, stepMode);
    } else if (__context_tag == to_underlying(Fields::kStepSize)) {
      err = DataModel::Decode(reader, stepSize);
    } else if (__context_tag == to_underlying(Fields::kTransitionTime)) {
      err = DataModel::Decode(reader, transitionTime);
    } else if (__context_tag == to_underlying(Fields::kOptionsMask)) {
      err = DataModel::Decode(reader, optionsMask);
    } else if (__context_tag == to_underlying(Fields::kOptionsOverride)) {
      err = DataModel::Decode(reader, optionsOverride);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace StepWithOnOff.
namespace StopWithOnOff {

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

    ReturnErrorOnFailure(err);
  }
}
} // namespace StopWithOnOff.
namespace MoveToClosestFrequency {

CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kFrequency), frequency);
  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::kFrequency)) {
      err = DataModel::Decode(reader, frequency);
    }

    ReturnErrorOnFailure(err);
  }
}
} // namespace MoveToClosestFrequency.
} // namespace Commands
} // namespace LevelControl
} // namespace Clusters
} // namespace app
} // namespace chip
