{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  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.

}}{{!

C++ header to store py3 specific Enum and Union type enum data

}}
{{^program:auto_migrate?}}
{{> common/auto_generated_c}}

#pragma once

#include <functional>
#include <folly/Range.h>

#include "{{program:includePrefix}}{{program:cpp_gen_path}}/{{program:name}}_data.h"
#include "{{program:includePrefix}}{{program:cpp_gen_path}}/{{program:name}}_types.h"
#include "{{program:includePrefix}}{{program:cpp_gen_path}}/{{program:name}}_metadata.h"
namespace thrift {
namespace py3 {


{{#program:filtered_structs}}
{{^struct:union?}}

template<>
inline void reset_field<{{#program:cppNamespaces}}::{{value}}{{/program:cppNamespaces}}::{{struct:name}}>(
    {{#program:cppNamespaces}}::{{value}}{{/program:cppNamespaces}}::{{struct:name}}& obj, uint16_t index) {
  switch (index) {
    {{#struct:py3_fields}}
    case {{field:index}}:
      {{^field:reference?}}
      obj.{{> types/field_cppname}}().copy_from(default_inst<{{#program:cppNamespaces}}::{{value}}{{/program:cppNamespaces}}::{{struct:name}}>().{{> types/field_cppname}}());
      {{/field:reference?}}
      {{#field:reference?}}
      obj.{{> types/field_cppname}}(){{^field:iobuf_ref?}}.{{/field:iobuf_ref?}}{{#field:iobuf_ref?}}->{{/field:iobuf_ref?}}reset();
      {{/field:reference?}}
      return;
    {{/struct:py3_fields}}
  }
}
{{/struct:union?}}
{{/program:filtered_structs}}
{{#program:filtered_structs}}

template<>
inline const std::unordered_map<std::string_view, std::string_view>& PyStructTraits<
    {{#program:cppNamespaces}}::{{value}}{{/program:cppNamespaces}}::{{struct:name}}>::namesmap() {
  static const folly::Indestructible<NamesMap> map {
    {
      {{#struct:py3_fields}}{{#field:hasPyName?}}
      {"{{field:name}}", "{{field:py_name}}"},
      {{/field:hasPyName?}}{{/struct:py3_fields}}
    }
  };
  return *map;
}
{{/program:filtered_structs}}
} // namespace py3
} // namespace thrift
{{/program:auto_migrate?}}
