<?hh
/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */

namespace test\fixtures\basic;

module hack.module.test;
/**
 * Original thrift enum:-
 * MyEnum
 */
<<\ThriftTypeInfo(shape('uri' => 'test.dev/fixtures/basic/MyEnum'))>>
enum MyEnum: int {
  MyValue1 = 0;
  MyValue2 = 1;
}

class MyEnum_TEnumStaticMetadata implements \IThriftEnumStaticMetadata {
  public static function getEnumMetadata()[]: \tmeta_ThriftEnum {
    return \tmeta_ThriftEnum::fromShape(
      shape(
        "name" => "module.MyEnum",
        "elements" => dict[
          0 => "MyValue1",
          1 => "MyValue2",
        ],
      )
    );
  }

  public static function getAllStructuredAnnotations()[write_props]: \TEnumAnnotations {
    return shape(
      'enum' => dict[],
      'constants' => dict[
      ],
    );
  }
}

/**
 * Original thrift enum:-
 * HackEnum
 */
<<\ThriftTypeInfo(shape('uri' => 'test.dev/fixtures/basic/HackEnum'))>>
enum RenamedEnum: int {
  Value1 = 0;
  renamedValue = 1;
}

class RenamedEnum_TEnumStaticMetadata implements \IThriftEnumStaticMetadata {
  public static function getEnumMetadata()[]: \tmeta_ThriftEnum {
    return \tmeta_ThriftEnum::fromShape(
      shape(
        "name" => "module.HackEnum",
        "elements" => dict[
          0 => "Value1",
          1 => "Value2",
        ],
      )
    );
  }

  public static function getAllStructuredAnnotations()[write_props]: \TEnumAnnotations {
    return shape(
      'enum' => dict[
        '\facebook\thrift\annotation\hack\Name' => \facebook\thrift\annotation\hack\Name::fromShape(
          shape(
            "name" => "RenamedEnum",
          )
        ),
      ],
      'constants' => dict[
        'Value2' => dict[
          '\facebook\thrift\annotation\hack\Name' => \facebook\thrift\annotation\hack\Name::fromShape(
            shape(
              "name" => "renamedValue",
            )
          ),
        ],
      ],
    );
  }
}

/**
 * Original thrift struct:-
 * MyStruct
 */
<<\ThriftTypeInfo(shape('uri' => 'test.dev/fixtures/basic/MyStruct'))>>
class MyStruct implements \IThriftSyncStruct, \IThriftStructMetadata, \IThriftShapishSyncStruct {
  use \ThriftSerializationTrait;

  const \ThriftStructTypes::TSpec SPEC = dict[
    1 => shape(
      'var' => 'MyIntField',
      'type' => \TType::I64,
    ),
    2 => shape(
      'var' => 'MyStringField',
      'type' => \TType::STRING,
    ),
    3 => shape(
      'var' => 'MyDataField',
      'type' => \TType::STRUCT,
      'class' => \test\fixtures\basic\MyDataItem::class,
    ),
    4 => shape(
      'var' => 'myEnum',
      'type' => \TType::I32,
      'enum' => \test\fixtures\basic\MyEnum::class,
    ),
    5 => shape(
      'var' => 'oneway',
      'type' => \TType::BOOL,
    ),
    6 => shape(
      'var' => 'readonly',
      'type' => \TType::BOOL,
    ),
    7 => shape(
      'var' => 'idempotent',
      'type' => \TType::BOOL,
    ),
  ];
  const dict<string, int> FIELDMAP = dict[
    'MyIntField' => 1,
    'MyStringField' => 2,
    'MyDataField' => 3,
    'myEnum' => 4,
    'oneway' => 5,
    'readonly' => 6,
    'idempotent' => 7,
  ];

  const type TConstructorShape = shape(
    ?'MyIntField' => ?int,
    ?'MyStringField' => ?string,
    ?'MyDataField' => ?\test\fixtures\basic\MyDataItem,
    ?'myEnum' => ?\test\fixtures\basic\MyEnum,
    ?'oneway' => ?bool,
    ?'readonly' => ?bool,
    ?'idempotent' => ?bool,
  );

  const type TShape = shape(
    'MyIntField' => int,
    'MyStringField' => string,
    ?'MyDataField' => ?\test\fixtures\basic\MyDataItem::TShape,
    ?'myEnum' => ?\test\fixtures\basic\MyEnum,
    'oneway' => bool,
    'readonly' => bool,
    'idempotent' => bool,
    ...
  );
  const int STRUCTURAL_ID = 4991963907375804067;
  /**
   * Original thrift field:-
   * 1: i64 MyIntField
   */
  public int $MyIntField;
  /**
   * Original thrift field:-
   * 2: string MyStringField
   */
  public string $MyStringField;
  /**
   * Original thrift field:-
   * 3: module.MyDataItem MyDataField
   */
  public ?\test\fixtures\basic\MyDataItem $MyDataField;
  /**
   * Original thrift field:-
   * 4: module.MyEnum myEnum
   */
  public ?\test\fixtures\basic\MyEnum $myEnum;
  /**
   * Original thrift field:-
   * 5: bool oneway
   */
  public bool $oneway;
  /**
   * Original thrift field:-
   * 6: bool readonly
   */
  public bool $readonly;
  /**
   * Original thrift field:-
   * 7: bool idempotent
   */
  public bool $idempotent;

  public function __construct(?int $MyIntField = null, ?string $MyStringField = null, ?\test\fixtures\basic\MyDataItem $MyDataField = null, ?\test\fixtures\basic\MyEnum $myEnum = null, ?bool $oneway = null, ?bool $readonly = null, ?bool $idempotent = null)[] {
    $this->MyIntField = $MyIntField ?? 0;
    $this->MyStringField = $MyStringField ?? '';
    $this->MyDataField = $MyDataField;
    $this->myEnum = $myEnum;
    $this->oneway = $oneway ?? false;
    $this->readonly = $readonly ?? false;
    $this->idempotent = $idempotent ?? false;
  }

  public static function withDefaultValues()[]: this {
    return new static();
  }

  public static function fromShape(self::TConstructorShape $shape)[]: this {
    return new static(
      Shapes::idx($shape, 'MyIntField'),
      Shapes::idx($shape, 'MyStringField'),
      Shapes::idx($shape, 'MyDataField'),
      Shapes::idx($shape, 'myEnum'),
      Shapes::idx($shape, 'oneway'),
      Shapes::idx($shape, 'readonly'),
      Shapes::idx($shape, 'idempotent'),
    );
  }

  public function getName()[]: string {
    return 'MyStruct';
  }

  public function clearTerseFields()[write_props]: void {
  }

  public static function getStructMetadata()[]: \tmeta_ThriftStruct {
    return \tmeta_ThriftStruct::fromShape(
      shape(
        "name" => "module.MyStruct",
        "fields" => vec[
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 1,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_primitive" => \tmeta_ThriftPrimitiveType::THRIFT_I64_TYPE,
                )
              ),
              "name" => "MyIntField",
            )
          ),
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 2,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_primitive" => \tmeta_ThriftPrimitiveType::THRIFT_STRING_TYPE,
                )
              ),
              "name" => "MyStringField",
            )
          ),
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 3,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_typedef" => \tmeta_ThriftTypedefType::fromShape(
                    shape(
                      "name" => "module.MyDataItem",
                      "underlyingType" => \tmeta_ThriftType::fromShape(
                        shape(
                          "t_struct" => \tmeta_ThriftStructType::fromShape(
                            shape(
                              "name" => "module.MyDataItem",
                            )
                          ),
                        )
                      ),
                    )
                  ),
                )
              ),
              "name" => "MyDataField",
            )
          ),
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 4,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_enum" => \tmeta_ThriftEnumType::fromShape(
                    shape(
                      "name" => "module.MyEnum",
                    )
                  ),
                )
              ),
              "name" => "myEnum",
            )
          ),
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 5,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_primitive" => \tmeta_ThriftPrimitiveType::THRIFT_BOOL_TYPE,
                )
              ),
              "name" => "oneway",
            )
          ),
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 6,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_primitive" => \tmeta_ThriftPrimitiveType::THRIFT_BOOL_TYPE,
                )
              ),
              "name" => "readonly",
            )
          ),
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 7,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_primitive" => \tmeta_ThriftPrimitiveType::THRIFT_BOOL_TYPE,
                )
              ),
              "name" => "idempotent",
            )
          ),
        ],
        "is_union" => false,
      )
    );
  }

  public static function getAllStructuredAnnotations()[write_props]: \TStructAnnotations {
    return shape(
      'struct' => dict[],
      'fields' => dict[
      ],
    );
  }

  public static function __fromShape(self::TShape $shape)[]: this {
    return new static(
      $shape['MyIntField'],
      $shape['MyStringField'],
      Shapes::idx($shape, 'MyDataField') === null ? null : (\test\fixtures\basic\MyDataItem::__fromShape($shape['MyDataField'])),
      Shapes::idx($shape, 'myEnum'),
      $shape['oneway'],
      $shape['readonly'],
      $shape['idempotent'],
    );
  }

  public function __toShape()[]: self::TShape {
    return shape(
      'MyIntField' => $this->MyIntField,
      'MyStringField' => $this->MyStringField,
      'MyDataField' => $this->MyDataField?->__toShape(),
      'myEnum' => $this->myEnum,
      'oneway' => $this->oneway,
      'readonly' => $this->readonly,
      'idempotent' => $this->idempotent,
    );
  }
  public function getInstanceKey()[write_props]: string {
    return \TCompactSerializer::serialize($this);
  }

  public function readFromJson(string $jsonText): void {
    $parsed = json_decode($jsonText, true);

    if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
      throw new \TProtocolException("Cannot parse the given json string.");
    }

    if (idx($parsed, 'MyIntField') !== null) {
      $this->MyIntField = HH\FIXME\UNSAFE_CAST<mixed, int>($parsed['MyIntField']);
    }
    if (idx($parsed, 'MyStringField') !== null) {
      $this->MyStringField = HH\FIXME\UNSAFE_CAST<mixed, string>($parsed['MyStringField']);
    }
    if (idx($parsed, 'MyDataField') !== null) {
      $_tmp0 = \json_encode(HH\FIXME\UNSAFE_CAST<mixed, \test\fixtures\basic\MyDataItem>($parsed['MyDataField']));
      $_tmp1 = \test\fixtures\basic\MyDataItem::withDefaultValues();
      $_tmp1->readFromJson($_tmp0);
      $this->MyDataField = $_tmp1;
    }
    if (idx($parsed, 'myEnum') !== null) {
      $this->myEnum = \test\fixtures\basic\MyEnum::coerce(HH\FIXME\UNSAFE_CAST<mixed, \test\fixtures\basic\MyEnum>($parsed['myEnum']));
    }
    if (idx($parsed, 'oneway') !== null) {
      $this->oneway = HH\FIXME\UNSAFE_CAST<mixed, bool>($parsed['oneway']);
    }
    if (idx($parsed, 'readonly') !== null) {
      $this->readonly = HH\FIXME\UNSAFE_CAST<mixed, bool>($parsed['readonly']);
    }
    if (idx($parsed, 'idempotent') !== null) {
      $this->idempotent = HH\FIXME\UNSAFE_CAST<mixed, bool>($parsed['idempotent']);
    }
  }

}

/**
 * Original thrift struct:-
 * MyDataItem
 */
<<\ThriftTypeInfo(shape('uri' => 'test.dev/fixtures/basic/MyDataItem'))>>
class MyDataItem implements \IThriftSyncStruct, \IThriftStructMetadata, \IThriftShapishSyncStruct {
  use \ThriftSerializationTrait;

  const \ThriftStructTypes::TSpec SPEC = dict[
  ];
  const dict<string, int> FIELDMAP = dict[
  ];

  const type TConstructorShape = shape(
  );

  const type TShape = shape(
    ...
  );
  const int STRUCTURAL_ID = 957977401221134810;

  public function __construct()[] {
  }

  public static function withDefaultValues()[]: this {
    return new static();
  }

  public static function fromShape(self::TConstructorShape $shape)[]: this {
    return new static(
    );
  }

  public function getName()[]: string {
    return 'MyDataItem';
  }

  public function clearTerseFields()[write_props]: void {
  }

  public static function getStructMetadata()[]: \tmeta_ThriftStruct {
    return \tmeta_ThriftStruct::fromShape(
      shape(
        "name" => "module.MyDataItem",
        "is_union" => false,
      )
    );
  }

  public static function getAllStructuredAnnotations()[write_props]: \TStructAnnotations {
    return shape(
      'struct' => dict[],
      'fields' => dict[
      ],
    );
  }

  public static function __fromShape(self::TShape $shape)[]: this {
    return new static(
    );
  }

  public function __toShape()[]: self::TShape {
    return shape(
    );
  }
  public function getInstanceKey()[write_props]: string {
    return \TCompactSerializer::serialize($this);
  }

  public function readFromJson(string $jsonText): void {
    $parsed = json_decode($jsonText, true);

    if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
      throw new \TProtocolException("Cannot parse the given json string.");
    }

  }

}

enum MyUnionEnum: int {
  _EMPTY_ = 0;
  myEnum = 1;
  myStruct = 2;
  myDataItem = 3;
}

/**
 * Original thrift struct:-
 * MyUnion
 */
<<\ThriftTypeInfo(shape('uri' => 'test.dev/fixtures/basic/MyUnion'))>>
class MyUnion implements \IThriftSyncStruct, \IThriftStructMetadata, \IThriftUnion<\test\fixtures\basic\MyUnionEnum>, \IThriftShapishSyncStruct {
  use \ThriftUnionSerializationTrait;

  const \ThriftStructTypes::TSpec SPEC = dict[
    1 => shape(
      'var' => 'myEnum',
      'union' => true,
      'type' => \TType::I32,
      'enum' => \test\fixtures\basic\MyEnum::class,
    ),
    2 => shape(
      'var' => 'myStruct',
      'union' => true,
      'type' => \TType::STRUCT,
      'class' => \test\fixtures\basic\MyStruct::class,
    ),
    3 => shape(
      'var' => 'myDataItem',
      'union' => true,
      'type' => \TType::STRUCT,
      'class' => \test\fixtures\basic\MyDataItem::class,
    ),
  ];
  const dict<string, int> FIELDMAP = dict[
    'myEnum' => 1,
    'myStruct' => 2,
    'myDataItem' => 3,
  ];

  const type TConstructorShape = shape(
    ?'myEnum' => ?\test\fixtures\basic\MyEnum,
    ?'myStruct' => ?\test\fixtures\basic\MyStruct,
    ?'myDataItem' => ?\test\fixtures\basic\MyDataItem,
  );

  const type TShape = shape(
    ?'myEnum' => ?\test\fixtures\basic\MyEnum,
    ?'myStruct' => ?\test\fixtures\basic\MyStruct::TShape,
    ?'myDataItem' => ?\test\fixtures\basic\MyDataItem::TShape,
    ...
  );
  const int STRUCTURAL_ID = 4641160414833587430;
  /**
   * Original thrift field:-
   * 1: module.MyEnum myEnum
   */
  public ?\test\fixtures\basic\MyEnum $myEnum;
  /**
   * Original thrift field:-
   * 2: module.MyStruct myStruct
   */
  public ?\test\fixtures\basic\MyStruct $myStruct;
  /**
   * Original thrift field:-
   * 3: module.MyDataItem myDataItem
   */
  public ?\test\fixtures\basic\MyDataItem $myDataItem;
  protected \test\fixtures\basic\MyUnionEnum $_type = \test\fixtures\basic\MyUnionEnum::_EMPTY_;

  public function __construct(?\test\fixtures\basic\MyEnum $myEnum = null, ?\test\fixtures\basic\MyStruct $myStruct = null, ?\test\fixtures\basic\MyDataItem $myDataItem = null)[] {
    $this->_type = \test\fixtures\basic\MyUnionEnum::_EMPTY_;
    if ($myEnum !== null) {
      $this->myEnum = $myEnum;
      $this->_type = \test\fixtures\basic\MyUnionEnum::myEnum;
    }
    if ($myStruct !== null) {
      $this->myStruct = $myStruct;
      $this->_type = \test\fixtures\basic\MyUnionEnum::myStruct;
    }
    if ($myDataItem !== null) {
      $this->myDataItem = $myDataItem;
      $this->_type = \test\fixtures\basic\MyUnionEnum::myDataItem;
    }
  }

  public static function withDefaultValues()[]: this {
    return new static();
  }

  public static function fromShape(self::TConstructorShape $shape)[]: this {
    return new static(
      Shapes::idx($shape, 'myEnum'),
      Shapes::idx($shape, 'myStruct'),
      Shapes::idx($shape, 'myDataItem'),
    );
  }

  public function getName()[]: string {
    return 'MyUnion';
  }

  public function getType()[]: \test\fixtures\basic\MyUnionEnum {
    return $this->_type;
  }

  public function reset()[write_props]: void {
    switch ($this->_type) {
      case \test\fixtures\basic\MyUnionEnum::myEnum:
        $this->myEnum = null;
        break;
      case \test\fixtures\basic\MyUnionEnum::myStruct:
        $this->myStruct = null;
        break;
      case \test\fixtures\basic\MyUnionEnum::myDataItem:
        $this->myDataItem = null;
        break;
      case \test\fixtures\basic\MyUnionEnum::_EMPTY_:
        break;
    }
    $this->_type = \test\fixtures\basic\MyUnionEnum::_EMPTY_;
  }

  public function set_myEnum(\test\fixtures\basic\MyEnum $myEnum)[write_props]: this {
    $this->reset();
    $this->_type = \test\fixtures\basic\MyUnionEnum::myEnum;
    $this->myEnum = $myEnum;
    return $this;
  }

  public function get_myEnum()[]: ?\test\fixtures\basic\MyEnum {
    return $this->myEnum;
  }

  public function getx_myEnum()[]: \test\fixtures\basic\MyEnum {
    invariant(
      $this->_type === \test\fixtures\basic\MyUnionEnum::myEnum,
      'get_myEnum called on an instance of MyUnion whose current type is %s',
      (string)$this->_type,
    );
    return $this->myEnum as nonnull;
  }

  public function set_myStruct(\test\fixtures\basic\MyStruct $myStruct)[write_props]: this {
    $this->reset();
    $this->_type = \test\fixtures\basic\MyUnionEnum::myStruct;
    $this->myStruct = $myStruct;
    return $this;
  }

  public function get_myStruct()[]: ?\test\fixtures\basic\MyStruct {
    return $this->myStruct;
  }

  public function getx_myStruct()[]: \test\fixtures\basic\MyStruct {
    invariant(
      $this->_type === \test\fixtures\basic\MyUnionEnum::myStruct,
      'get_myStruct called on an instance of MyUnion whose current type is %s',
      (string)$this->_type,
    );
    return $this->myStruct as nonnull;
  }

  public function set_myDataItem(\test\fixtures\basic\MyDataItem $myDataItem)[write_props]: this {
    $this->reset();
    $this->_type = \test\fixtures\basic\MyUnionEnum::myDataItem;
    $this->myDataItem = $myDataItem;
    return $this;
  }

  public function get_myDataItem()[]: ?\test\fixtures\basic\MyDataItem {
    return $this->myDataItem;
  }

  public function getx_myDataItem()[]: \test\fixtures\basic\MyDataItem {
    invariant(
      $this->_type === \test\fixtures\basic\MyUnionEnum::myDataItem,
      'get_myDataItem called on an instance of MyUnion whose current type is %s',
      (string)$this->_type,
    );
    return $this->myDataItem as nonnull;
  }

  public function clearTerseFields()[write_props]: void {
  }

  public static function getStructMetadata()[]: \tmeta_ThriftStruct {
    return \tmeta_ThriftStruct::fromShape(
      shape(
        "name" => "module.MyUnion",
        "fields" => vec[
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 1,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_enum" => \tmeta_ThriftEnumType::fromShape(
                    shape(
                      "name" => "module.MyEnum",
                    )
                  ),
                )
              ),
              "name" => "myEnum",
            )
          ),
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 2,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_struct" => \tmeta_ThriftStructType::fromShape(
                    shape(
                      "name" => "module.MyStruct",
                    )
                  ),
                )
              ),
              "name" => "myStruct",
            )
          ),
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 3,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_struct" => \tmeta_ThriftStructType::fromShape(
                    shape(
                      "name" => "module.MyDataItem",
                    )
                  ),
                )
              ),
              "name" => "myDataItem",
            )
          ),
        ],
        "is_union" => true,
      )
    );
  }

  public static function getAllStructuredAnnotations()[write_props]: \TStructAnnotations {
    return shape(
      'struct' => dict[],
      'fields' => dict[
      ],
    );
  }

  public static function __fromShape(self::TShape $shape)[]: this {
    return new static(
      Shapes::idx($shape, 'myEnum'),
      Shapes::idx($shape, 'myStruct') === null ? null : (\test\fixtures\basic\MyStruct::__fromShape($shape['myStruct'])),
      Shapes::idx($shape, 'myDataItem') === null ? null : (\test\fixtures\basic\MyDataItem::__fromShape($shape['myDataItem'])),
    );
  }

  public function __toShape()[]: self::TShape {
    return shape(
      'myEnum' => $this->myEnum,
      'myStruct' => $this->myStruct?->__toShape(),
      'myDataItem' => $this->myDataItem?->__toShape(),
    );
  }
  public function getInstanceKey()[write_props]: string {
    return \TCompactSerializer::serialize($this);
  }

  public function readFromJson(string $jsonText): void {
    $this->_type = \test\fixtures\basic\MyUnionEnum::_EMPTY_;
    $parsed = json_decode($jsonText, true);

    if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
      throw new \TProtocolException("Cannot parse the given json string.");
    }

    if (idx($parsed, 'myEnum') !== null) {
      $this->myEnum = \test\fixtures\basic\MyEnum::coerce(HH\FIXME\UNSAFE_CAST<mixed, \test\fixtures\basic\MyEnum>($parsed['myEnum']));
      $this->_type = \test\fixtures\basic\MyUnionEnum::myEnum;
    }
    if (idx($parsed, 'myStruct') !== null) {
      $_tmp0 = \json_encode(HH\FIXME\UNSAFE_CAST<mixed, \test\fixtures\basic\MyStruct>($parsed['myStruct']));
      $_tmp1 = \test\fixtures\basic\MyStruct::withDefaultValues();
      $_tmp1->readFromJson($_tmp0);
      $this->myStruct = $_tmp1;
      $this->_type = \test\fixtures\basic\MyUnionEnum::myStruct;
    }
    if (idx($parsed, 'myDataItem') !== null) {
      $_tmp2 = \json_encode(HH\FIXME\UNSAFE_CAST<mixed, \test\fixtures\basic\MyDataItem>($parsed['myDataItem']));
      $_tmp3 = \test\fixtures\basic\MyDataItem::withDefaultValues();
      $_tmp3->readFromJson($_tmp2);
      $this->myDataItem = $_tmp3;
      $this->_type = \test\fixtures\basic\MyUnionEnum::myDataItem;
    }
  }

}

/**
 * Original thrift struct:-
 * ReservedKeyword
 */
<<\ThriftTypeInfo(shape('uri' => 'test.dev/fixtures/basic/ReservedKeyword'))>>
class MyRenamedStruct implements \IThriftSyncStruct, \IThriftStructMetadata, \IThriftShapishSyncStruct {
  use \ThriftSerializationTrait;

  const \ThriftStructTypes::TSpec SPEC = dict[
    1 => shape(
      'var' => 'reserved_field',
      'type' => \TType::I32,
    ),
  ];
  const dict<string, int> FIELDMAP = dict[
    'reserved_field' => 1,
  ];

  const type TConstructorShape = shape(
    ?'reserved_field' => ?int,
  );

  const type TShape = shape(
    'reserved_field' => int,
    ...
  );
  const int STRUCTURAL_ID = 9144321583101923955;
  /**
   * Original thrift field:-
   * 1: i32 reserved_field
   */
  public int $reserved_field;

  public function __construct(?int $reserved_field = null)[] {
    $this->reserved_field = $reserved_field ?? 0;
  }

  public static function withDefaultValues()[]: this {
    return new static();
  }

  public static function fromShape(self::TConstructorShape $shape)[]: this {
    return new static(
      Shapes::idx($shape, 'reserved_field'),
    );
  }

  public function getName()[]: string {
    return 'MyRenamedStruct';
  }

  public function clearTerseFields()[write_props]: void {
  }

  public static function getStructMetadata()[]: \tmeta_ThriftStruct {
    return \tmeta_ThriftStruct::fromShape(
      shape(
        "name" => "module.ReservedKeyword",
        "fields" => vec[
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 1,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_primitive" => \tmeta_ThriftPrimitiveType::THRIFT_I32_TYPE,
                )
              ),
              "name" => "reserved_field",
            )
          ),
        ],
        "is_union" => false,
      )
    );
  }

  public static function getAllStructuredAnnotations()[write_props]: \TStructAnnotations {
    return shape(
      'struct' => dict[
        '\facebook\thrift\annotation\hack\Name' => \facebook\thrift\annotation\hack\Name::fromShape(
          shape(
            "name" => "MyRenamedStruct",
          )
        ),
      ],
      'fields' => dict[
        'reserved_field' => shape(
          'field' => dict[
            '\facebook\thrift\annotation\hack\Name' => \facebook\thrift\annotation\hack\Name::fromShape(
              shape(
                "name" => "renamed_field",
              )
            ),
          ],
          'type' => dict[],
        ),
      ],
    );
  }

  public static function __fromShape(self::TShape $shape)[]: this {
    return new static(
      $shape['reserved_field'],
    );
  }

  public function __toShape()[]: self::TShape {
    return shape(
      'reserved_field' => $this->reserved_field,
    );
  }
  public function getInstanceKey()[write_props]: string {
    return \TCompactSerializer::serialize($this);
  }

  public function readFromJson(string $jsonText): void {
    $parsed = json_decode($jsonText, true);

    if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
      throw new \TProtocolException("Cannot parse the given json string.");
    }

    if (idx($parsed, 'reserved_field') !== null) {
      $_tmp0 = (int)HH\FIXME\UNSAFE_CAST<mixed, int>($parsed['reserved_field']);
      if ($_tmp0 > 0x7fffffff) {
        throw new \TProtocolException("number exceeds limit in field");
      } else {
        $this->reserved_field = (int)$_tmp0;
      }
    }
  }

}

enum MyRenamedUnionEnum: int {
  _EMPTY_ = 0;
  reserved_field = 1;
}

/**
 * Original thrift struct:-
 * UnionToBeRenamed
 */
<<\ThriftTypeInfo(shape('uri' => 'test.dev/fixtures/basic/UnionToBeRenamed'))>>
class MyRenamedUnion implements \IThriftSyncStruct, \IThriftStructMetadata, \IThriftUnion<\test\fixtures\basic\MyRenamedUnionEnum>, \IThriftShapishSyncStruct {
  use \ThriftUnionSerializationTrait;

  const \ThriftStructTypes::TSpec SPEC = dict[
    1 => shape(
      'var' => 'reserved_field',
      'union' => true,
      'type' => \TType::I32,
    ),
  ];
  const dict<string, int> FIELDMAP = dict[
    'reserved_field' => 1,
  ];

  const type TConstructorShape = shape(
    ?'reserved_field' => ?int,
  );

  const type TShape = shape(
    ?'reserved_field' => ?int,
    ...
  );
  const int STRUCTURAL_ID = 9144321583101923955;
  /**
   * Original thrift field:-
   * 1: i32 reserved_field
   */
  public ?int $reserved_field;
  protected \test\fixtures\basic\MyRenamedUnionEnum $_type = \test\fixtures\basic\MyRenamedUnionEnum::_EMPTY_;

  public function __construct(?int $reserved_field = null)[] {
    $this->_type = \test\fixtures\basic\MyRenamedUnionEnum::_EMPTY_;
    if ($reserved_field !== null) {
      $this->reserved_field = $reserved_field;
      $this->_type = \test\fixtures\basic\MyRenamedUnionEnum::reserved_field;
    }
  }

  public static function withDefaultValues()[]: this {
    return new static();
  }

  public static function fromShape(self::TConstructorShape $shape)[]: this {
    return new static(
      Shapes::idx($shape, 'reserved_field'),
    );
  }

  public function getName()[]: string {
    return 'MyRenamedUnion';
  }

  public function getType()[]: \test\fixtures\basic\MyRenamedUnionEnum {
    return $this->_type;
  }

  public function reset()[write_props]: void {
    switch ($this->_type) {
      case \test\fixtures\basic\MyRenamedUnionEnum::reserved_field:
        $this->reserved_field = null;
        break;
      case \test\fixtures\basic\MyRenamedUnionEnum::_EMPTY_:
        break;
    }
    $this->_type = \test\fixtures\basic\MyRenamedUnionEnum::_EMPTY_;
  }

  public function set_reserved_field(int $reserved_field)[write_props]: this {
    $this->reset();
    $this->_type = \test\fixtures\basic\MyRenamedUnionEnum::reserved_field;
    $this->reserved_field = $reserved_field;
    return $this;
  }

  public function get_reserved_field()[]: ?int {
    return $this->reserved_field;
  }

  public function getx_reserved_field()[]: int {
    invariant(
      $this->_type === \test\fixtures\basic\MyRenamedUnionEnum::reserved_field,
      'get_reserved_field called on an instance of UnionToBeRenamed whose current type is %s',
      (string)$this->_type,
    );
    return $this->reserved_field as nonnull;
  }

  public function clearTerseFields()[write_props]: void {
  }

  public static function getStructMetadata()[]: \tmeta_ThriftStruct {
    return \tmeta_ThriftStruct::fromShape(
      shape(
        "name" => "module.UnionToBeRenamed",
        "fields" => vec[
          \tmeta_ThriftField::fromShape(
            shape(
              "id" => 1,
              "type" => \tmeta_ThriftType::fromShape(
                shape(
                  "t_primitive" => \tmeta_ThriftPrimitiveType::THRIFT_I32_TYPE,
                )
              ),
              "name" => "reserved_field",
            )
          ),
        ],
        "is_union" => true,
      )
    );
  }

  public static function getAllStructuredAnnotations()[write_props]: \TStructAnnotations {
    return shape(
      'struct' => dict[
        '\facebook\thrift\annotation\hack\Name' => \facebook\thrift\annotation\hack\Name::fromShape(
          shape(
            "name" => "MyRenamedUnion",
          )
        ),
      ],
      'fields' => dict[
        'reserved_field' => shape(
          'field' => dict[
            '\facebook\thrift\annotation\hack\Name' => \facebook\thrift\annotation\hack\Name::fromShape(
              shape(
                "name" => "renamed_field",
              )
            ),
          ],
          'type' => dict[],
        ),
      ],
    );
  }

  public static function __fromShape(self::TShape $shape)[]: this {
    return new static(
      Shapes::idx($shape, 'reserved_field'),
    );
  }

  public function __toShape()[]: self::TShape {
    return shape(
      'reserved_field' => $this->reserved_field,
    );
  }
  public function getInstanceKey()[write_props]: string {
    return \TCompactSerializer::serialize($this);
  }

  public function readFromJson(string $jsonText): void {
    $this->_type = \test\fixtures\basic\UnionToBeRenamedEnum::_EMPTY_;
    $parsed = json_decode($jsonText, true);

    if ($parsed === null || !($parsed is KeyedContainer<_, _>)) {
      throw new \TProtocolException("Cannot parse the given json string.");
    }

    if (idx($parsed, 'reserved_field') !== null) {
      $_tmp0 = (int)HH\FIXME\UNSAFE_CAST<mixed, int>($parsed['reserved_field']);
      if ($_tmp0 > 0x7fffffff) {
        throw new \TProtocolException("number exceeds limit in field");
      } else {
        $this->reserved_field = (int)$_tmp0;
      }
      $this->_type = \test\fixtures\basic\UnionToBeRenamedEnum::reserved_field;
    }
  }

}