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

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

namespace chip {
namespace app {
namespace Clusters {
namespace WaterValveData {
namespace Structs {

namespace ValveSessionStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kWeekdays), weekdays);
  encoder.Encode(to_underlying(Fields::kHour), hour);
  encoder.Encode(to_underlying(Fields::kMinute), minute);
  encoder.Encode(to_underlying(Fields::kVolume), volume);
  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::kWeekdays)) {
      err = DataModel::Decode(reader, weekdays);
    } else if (__context_tag == to_underlying(Fields::kHour)) {
      err = DataModel::Decode(reader, hour);
    } else if (__context_tag == to_underlying(Fields::kMinute)) {
      err = DataModel::Decode(reader, minute);
    } else if (__context_tag == to_underlying(Fields::kVolume)) {
      err = DataModel::Decode(reader, volume);
    } else if (__context_tag == to_underlying(Fields::kDuration)) {
      err = DataModel::Decode(reader, duration);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace ValveSessionStruct

namespace ValveSessionStateStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kSession), session);
  encoder.Encode(to_underlying(Fields::kState), state);
  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::kSession)) {
      err = DataModel::Decode(reader, session);
    } else if (__context_tag == to_underlying(Fields::kState)) {
      err = DataModel::Decode(reader, state);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace ValveSessionStateStruct

namespace ValveFreezeStateStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kFreezed), freezed);
  encoder.Encode(to_underlying(Fields::kTimestamp), timestamp);
  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::kFreezed)) {
      err = DataModel::Decode(reader, freezed);
    } else if (__context_tag == to_underlying(Fields::kTimestamp)) {
      err = DataModel::Decode(reader, timestamp);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace ValveFreezeStateStruct

namespace ValveSessionLogStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kBegin), begin);
  encoder.Encode(to_underlying(Fields::kEnd), end);
  encoder.Encode(to_underlying(Fields::kVolume), volume);
  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::kBegin)) {
      err = DataModel::Decode(reader, begin);
    } else if (__context_tag == to_underlying(Fields::kEnd)) {
      err = DataModel::Decode(reader, end);
    } else if (__context_tag == to_underlying(Fields::kVolume)) {
      err = DataModel::Decode(reader, volume);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace ValveSessionLogStruct

namespace ValveTemperatureStateStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kTemperature), temperature);
  encoder.Encode(to_underlying(Fields::kTimestamp), timestamp);
  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::kTemperature)) {
      err = DataModel::Decode(reader, temperature);
    } else if (__context_tag == to_underlying(Fields::kTimestamp)) {
      err = DataModel::Decode(reader, timestamp);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace ValveTemperatureStateStruct

namespace WaterUsageStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const {
  DataModel::WrappedStructEncoder encoder{aWriter, aTag};
  encoder.Encode(to_underlying(Fields::kHour), hour);
  encoder.Encode(to_underlying(Fields::kToday), today);
  encoder.Encode(to_underlying(Fields::kYesterday), yesterday);
  encoder.Encode(to_underlying(Fields::kCurrentWeek), currentWeek);
  encoder.Encode(to_underlying(Fields::kLastWeek), lastWeek);
  encoder.Encode(to_underlying(Fields::kCurrentMonth), currentMonth);
  encoder.Encode(to_underlying(Fields::kLastMonth), lastMonth);
  encoder.Encode(to_underlying(Fields::kCurrentYear), currentYear);
  encoder.Encode(to_underlying(Fields::kLastYear), lastYear);
  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::kHour)) {
      err = DataModel::Decode(reader, hour);
    } else if (__context_tag == to_underlying(Fields::kToday)) {
      err = DataModel::Decode(reader, today);
    } else if (__context_tag == to_underlying(Fields::kYesterday)) {
      err = DataModel::Decode(reader, yesterday);
    } else if (__context_tag == to_underlying(Fields::kCurrentWeek)) {
      err = DataModel::Decode(reader, currentWeek);
    } else if (__context_tag == to_underlying(Fields::kLastWeek)) {
      err = DataModel::Decode(reader, lastWeek);
    } else if (__context_tag == to_underlying(Fields::kCurrentMonth)) {
      err = DataModel::Decode(reader, currentMonth);
    } else if (__context_tag == to_underlying(Fields::kLastMonth)) {
      err = DataModel::Decode(reader, lastMonth);
    } else if (__context_tag == to_underlying(Fields::kCurrentYear)) {
      err = DataModel::Decode(reader, currentYear);
    } else if (__context_tag == to_underlying(Fields::kLastYear)) {
      err = DataModel::Decode(reader, lastYear);
    }

    ReturnErrorOnFailure(err);
  }
}

} // namespace WaterUsageStruct
} // namespace Structs
} // namespace WaterValveData
} // namespace Clusters
} // namespace app
} // namespace chip
