// Copyright 2024 CloudWeGo 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.

// Code generated by thriftgo (0.3.15). DO NOT EDIT.

package thrift_reflection_test

import (
	"context"
	"database/sql"
	"database/sql/driver"
	"fmt"
)

const (
	MYCONST = "hello"

	MYINTCONST = 123

	MYFLOATCONST = 123.333

	MYBOOLCONST = true

	MYBYTECONST = 1
)

var (
	MYBINARYCONST = []byte("1")

	MYLISTCONST = []string{
		"a",
		"b",
		"c",
	}

	MYMAPCONST = map[string]string{
		"k1": "v1",
		"k2": "v2",
		"k3": "v3",
	}
)

type Gender int64

const (
	Gender_MALE   Gender = 0
	Gender_FEMALE Gender = 1
)

func (p Gender) String() string {
	switch p {
	case Gender_MALE:
		return "MALE"
	case Gender_FEMALE:
		return "FEMALE"
	}
	return "<UNSET>"
}

func GenderFromString(s string) (Gender, error) {
	switch s {
	case "MALE":
		return Gender_MALE, nil
	case "FEMALE":
		return Gender_FEMALE, nil
	}
	return Gender(0), fmt.Errorf("not a valid Gender string")
}

func GenderPtr(v Gender) *Gender { return &v }
func (p *Gender) Scan(value interface{}) (err error) {
	var result sql.NullInt64
	err = result.Scan(value)
	*p = Gender(result.Int64)
	return
}

func (p *Gender) Value() (driver.Value, error) {
	if p == nil {
		return nil, nil
	}
	return int64(*p), nil
}

type Size int64

const (
	Size_S   Size = 0
	Size_M   Size = 1
	Size_L   Size = 2
	Size_XL  Size = 3
	Size_XXL Size = 4
)

func (p Size) String() string {
	switch p {
	case Size_S:
		return "S"
	case Size_M:
		return "M"
	case Size_L:
		return "L"
	case Size_XL:
		return "XL"
	case Size_XXL:
		return "XXL"
	}
	return "<UNSET>"
}

func SizeFromString(s string) (Size, error) {
	switch s {
	case "S":
		return Size_S, nil
	case "M":
		return Size_M, nil
	case "L":
		return Size_L, nil
	case "XL":
		return Size_XL, nil
	case "XXL":
		return Size_XXL, nil
	}
	return Size(0), fmt.Errorf("not a valid Size string")
}

func SizePtr(v Size) *Size { return &v }
func (p *Size) Scan(value interface{}) (err error) {
	var result sql.NullInt64
	err = result.Scan(value)
	*p = Size(result.Int64)
	return
}

func (p *Size) Value() (driver.Value, error) {
	if p == nil {
		return nil, nil
	}
	return int64(*p), nil
}

type SpecialString = string

type SpecialPerson = Person

func NewSpecialPerson() *SpecialPerson {
	return (*SpecialPerson)(NewPerson())
}

type IDCard struct {
	Number string `thrift:"number,1,required" json:"number"`
	Age    int8   `thrift:"age,2,required" json:"age"`
}

func NewIDCard() *IDCard {
	return &IDCard{}
}

func (p *IDCard) InitDefault() {
}

func (p *IDCard) GetNumber() (v string) {
	return p.Number
}

func (p *IDCard) GetAge() (v int8) {
	return p.Age
}

func (p *IDCard) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("IDCard(%+v)", *p)
}

var fieldIDToName_IDCard = map[int16]string{
	1: "number",
	2: "age",
}

type Person struct {
	Name         string        `thrift:"name,1,required" json:"name"`
	ID           *IDCard       `thrift:"id,2,required" json:"id"`
	Gender       Gender        `thrift:"gender,3,required" json:"gender"`
	Exp          *MyException  `thrift:"exp,4,required" json:"exp"`
	Uni          *MyUnion      `thrift:"uni,5,required" json:"uni"`
	TypedefValue SpecialString `thrift:"typedefValue,6,required" json:"typedefValue"`
	DefaultValue string        `thrift:"defaultValue,7,required" json:"defaultValue"`
	DefaultConst string        `thrift:"defaultConst,8,required" json:"defaultConst"`
}

func NewPerson() *Person {
	return &Person{

		DefaultValue: "123321",
		DefaultConst: MYCONST,
	}
}

func (p *Person) InitDefault() {
	p.DefaultValue = "123321"
	p.DefaultConst = MYCONST
}

func (p *Person) GetName() (v string) {
	return p.Name
}

var Person_ID_DEFAULT *IDCard

func (p *Person) GetID() (v *IDCard) {
	if !p.IsSetID() {
		return Person_ID_DEFAULT
	}
	return p.ID
}

func (p *Person) GetGender() (v Gender) {
	return p.Gender
}

var Person_Exp_DEFAULT *MyException

func (p *Person) GetExp() (v *MyException) {
	if !p.IsSetExp() {
		return Person_Exp_DEFAULT
	}
	return p.Exp
}

var Person_Uni_DEFAULT *MyUnion

func (p *Person) GetUni() (v *MyUnion) {
	if !p.IsSetUni() {
		return Person_Uni_DEFAULT
	}
	return p.Uni
}

func (p *Person) GetTypedefValue() (v SpecialString) {
	return p.TypedefValue
}

func (p *Person) GetDefaultValue() (v string) {
	return p.DefaultValue
}

func (p *Person) GetDefaultConst() (v string) {
	return p.DefaultConst
}

func (p *Person) IsSetID() bool {
	return p.ID != nil
}

func (p *Person) IsSetExp() bool {
	return p.Exp != nil
}

func (p *Person) IsSetUni() bool {
	return p.Uni != nil
}

func (p *Person) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("Person(%+v)", *p)
}

var fieldIDToName_Person = map[int16]string{
	1: "name",
	2: "id",
	3: "gender",
	4: "exp",
	5: "uni",
	6: "typedefValue",
	7: "defaultValue",
	8: "defaultConst",
}

type A0 struct {
	F1 string             `thrift:"f1,1,required" json:"f1"`
	F2 *B                 `thrift:"f2,2,required" json:"f2"`
	F3 map[string]*C      `thrift:"f3,3,required" json:"f3"`
	F4 map[*D]map[*E][]*F `thrift:"f4,4,required" json:"f4"`
}

func NewA0() *A0 {
	return &A0{}
}

func (p *A0) InitDefault() {
}

func (p *A0) GetF1() (v string) {
	return p.F1
}

var A0_F2_DEFAULT *B

func (p *A0) GetF2() (v *B) {
	if !p.IsSetF2() {
		return A0_F2_DEFAULT
	}
	return p.F2
}

func (p *A0) GetF3() (v map[string]*C) {
	return p.F3
}

func (p *A0) GetF4() (v map[*D]map[*E][]*F) {
	return p.F4
}

func (p *A0) IsSetF2() bool {
	return p.F2 != nil
}

func (p *A0) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("A0(%+v)", *p)
}

var fieldIDToName_A0 = map[int16]string{
	1: "f1",
	2: "f2",
	3: "f3",
	4: "f4",
}

type A1 struct {
	F1 string `thrift:"f1,1,required" json:"f1"`
	F2 *A2    `thrift:"f2,2,required" json:"f2"`
}

func NewA1() *A1 {
	return &A1{}
}

func (p *A1) InitDefault() {
}

func (p *A1) GetF1() (v string) {
	return p.F1
}

var A1_F2_DEFAULT *A2

func (p *A1) GetF2() (v *A2) {
	if !p.IsSetF2() {
		return A1_F2_DEFAULT
	}
	return p.F2
}

func (p *A1) IsSetF2() bool {
	return p.F2 != nil
}

func (p *A1) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("A1(%+v)", *p)
}

var fieldIDToName_A1 = map[int16]string{
	1: "f1",
	2: "f2",
}

type A2 struct {
	F1 string `thrift:"f1,1,required" json:"f1"`
}

func NewA2() *A2 {
	return &A2{}
}

func (p *A2) InitDefault() {
}

func (p *A2) GetF1() (v string) {
	return p.F1
}

func (p *A2) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("A2(%+v)", *p)
}

var fieldIDToName_A2 = map[int16]string{
	1: "f1",
}

type A3 struct {
	F1 string `thrift:"f1,1,required" json:"f1"`
}

func NewA3() *A3 {
	return &A3{}
}

func (p *A3) InitDefault() {
}

func (p *A3) GetF1() (v string) {
	return p.F1
}

func (p *A3) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("A3(%+v)", *p)
}

var fieldIDToName_A3 = map[int16]string{
	1: "f1",
}

type B struct {
	F1 *B1 `thrift:"f1,1,required" json:"f1"`
	F2 *E  `thrift:"f2,2,required" json:"f2"`
}

func NewB() *B {
	return &B{}
}

func (p *B) InitDefault() {
}

var B_F1_DEFAULT *B1

func (p *B) GetF1() (v *B1) {
	if !p.IsSetF1() {
		return B_F1_DEFAULT
	}
	return p.F1
}

var B_F2_DEFAULT *E

func (p *B) GetF2() (v *E) {
	if !p.IsSetF2() {
		return B_F2_DEFAULT
	}
	return p.F2
}

func (p *B) IsSetF1() bool {
	return p.F1 != nil
}

func (p *B) IsSetF2() bool {
	return p.F2 != nil
}

func (p *B) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("B(%+v)", *p)
}

var fieldIDToName_B = map[int16]string{
	1: "f1",
	2: "f2",
}

type B1 struct {
	Name string `thrift:"name,1,required" json:"name"`
}

func NewB1() *B1 {
	return &B1{}
}

func (p *B1) InitDefault() {
}

func (p *B1) GetName() (v string) {
	return p.Name
}

func (p *B1) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("B1(%+v)", *p)
}

var fieldIDToName_B1 = map[int16]string{
	1: "name",
}

type C struct {
	F1 *B `thrift:"f1,1,required" json:"f1"`
}

func NewC() *C {
	return &C{}
}

func (p *C) InitDefault() {
}

var C_F1_DEFAULT *B

func (p *C) GetF1() (v *B) {
	if !p.IsSetF1() {
		return C_F1_DEFAULT
	}
	return p.F1
}

func (p *C) IsSetF1() bool {
	return p.F1 != nil
}

func (p *C) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("C(%+v)", *p)
}

var fieldIDToName_C = map[int16]string{
	1: "f1",
}

type D struct {
	F1 map[*D1]*D2 `thrift:"f1,1,required" json:"f1"`
}

func NewD() *D {
	return &D{}
}

func (p *D) InitDefault() {
}

func (p *D) GetF1() (v map[*D1]*D2) {
	return p.F1
}

func (p *D) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("D(%+v)", *p)
}

var fieldIDToName_D = map[int16]string{
	1: "f1",
}

type D1 struct {
	Name string `thrift:"name,1,required" json:"name"`
}

func NewD1() *D1 {
	return &D1{}
}

func (p *D1) InitDefault() {
}

func (p *D1) GetName() (v string) {
	return p.Name
}

func (p *D1) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("D1(%+v)", *p)
}

var fieldIDToName_D1 = map[int16]string{
	1: "name",
}

type D2 struct {
	Name string `thrift:"name,1,required" json:"name"`
}

func NewD2() *D2 {
	return &D2{}
}

func (p *D2) InitDefault() {
}

func (p *D2) GetName() (v string) {
	return p.Name
}

func (p *D2) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("D2(%+v)", *p)
}

var fieldIDToName_D2 = map[int16]string{
	1: "name",
}

type E struct {
	F1 *C `thrift:"f1,1,required" json:"f1"`
}

func NewE() *E {
	return &E{}
}

func (p *E) InitDefault() {
}

var E_F1_DEFAULT *C

func (p *E) GetF1() (v *C) {
	if !p.IsSetF1() {
		return E_F1_DEFAULT
	}
	return p.F1
}

func (p *E) IsSetF1() bool {
	return p.F1 != nil
}

func (p *E) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("E(%+v)", *p)
}

var fieldIDToName_E = map[int16]string{
	1: "f1",
}

type F struct {
	Name string `thrift:"name,1,required" json:"name"`
}

func NewF() *F {
	return &F{}
}

func (p *F) InitDefault() {
}

func (p *F) GetName() (v string) {
	return p.Name
}

func (p *F) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("F(%+v)", *p)
}

var fieldIDToName_F = map[int16]string{
	1: "name",
}

type MyUnion struct {
	Number *string `thrift:"number,1,optional" json:"number,omitempty"`
	Age    *int8   `thrift:"age,2,optional" json:"age,omitempty"`
}

func NewMyUnion() *MyUnion {
	return &MyUnion{}
}

func (p *MyUnion) InitDefault() {
}

var MyUnion_Number_DEFAULT string

func (p *MyUnion) GetNumber() (v string) {
	if !p.IsSetNumber() {
		return MyUnion_Number_DEFAULT
	}
	return *p.Number
}

var MyUnion_Age_DEFAULT int8

func (p *MyUnion) GetAge() (v int8) {
	if !p.IsSetAge() {
		return MyUnion_Age_DEFAULT
	}
	return *p.Age
}

func (p *MyUnion) CountSetFieldsMyUnion() int {
	count := 0
	if p.IsSetNumber() {
		count++
	}
	if p.IsSetAge() {
		count++
	}
	return count
}

func (p *MyUnion) IsSetNumber() bool {
	return p.Number != nil
}

func (p *MyUnion) IsSetAge() bool {
	return p.Age != nil
}

func (p *MyUnion) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyUnion(%+v)", *p)
}

var fieldIDToName_MyUnion = map[int16]string{
	1: "number",
	2: "age",
}

type MyException struct {
	Msg  string `thrift:"msg,1,required" json:"msg"`
	Code int8   `thrift:"code,2,required" json:"code"`
}

func NewMyException() *MyException {
	return &MyException{}
}

func (p *MyException) InitDefault() {
}

func (p *MyException) GetMsg() (v string) {
	return p.Msg
}

func (p *MyException) GetCode() (v int8) {
	return p.Code
}

func (p *MyException) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyException(%+v)", *p)
}
func (p *MyException) Error() string {
	return p.String()
}

var fieldIDToName_MyException = map[int16]string{
	1: "msg",
	2: "code",
}

type MyService interface {
	MyParentService

	M1(ctx context.Context, p_ *Person) (r string, err error)

	M2(ctx context.Context, p2 *Person) (r string, err error)

	M3(ctx context.Context, a0 *A0, a3 *A3) (r *A1, err error)
}

type MyServiceM1Args struct {
	P *Person `thrift:"p,1,required" json:"p"`
}

func NewMyServiceM1Args() *MyServiceM1Args {
	return &MyServiceM1Args{}
}

func (p *MyServiceM1Args) InitDefault() {
}

var MyServiceM1Args_P_DEFAULT *Person

func (p *MyServiceM1Args) GetP() (v *Person) {
	if !p.IsSetP() {
		return MyServiceM1Args_P_DEFAULT
	}
	return p.P
}

func (p *MyServiceM1Args) IsSetP() bool {
	return p.P != nil
}

func (p *MyServiceM1Args) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyServiceM1Args(%+v)", *p)
}

var fieldIDToName_MyServiceM1Args = map[int16]string{
	1: "p",
}

type MyServiceM1Result struct {
	Success *string `thrift:"success,0,optional" json:"success,omitempty"`
}

func NewMyServiceM1Result() *MyServiceM1Result {
	return &MyServiceM1Result{}
}

func (p *MyServiceM1Result) InitDefault() {
}

var MyServiceM1Result_Success_DEFAULT string

func (p *MyServiceM1Result) GetSuccess() (v string) {
	if !p.IsSetSuccess() {
		return MyServiceM1Result_Success_DEFAULT
	}
	return *p.Success
}

func (p *MyServiceM1Result) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *MyServiceM1Result) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyServiceM1Result(%+v)", *p)
}

var fieldIDToName_MyServiceM1Result = map[int16]string{
	0: "success",
}

type MyServiceM2Args struct {
	P2 *Person `thrift:"p2,1,required" json:"p2"`
}

func NewMyServiceM2Args() *MyServiceM2Args {
	return &MyServiceM2Args{}
}

func (p *MyServiceM2Args) InitDefault() {
}

var MyServiceM2Args_P2_DEFAULT *Person

func (p *MyServiceM2Args) GetP2() (v *Person) {
	if !p.IsSetP2() {
		return MyServiceM2Args_P2_DEFAULT
	}
	return p.P2
}

func (p *MyServiceM2Args) IsSetP2() bool {
	return p.P2 != nil
}

func (p *MyServiceM2Args) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyServiceM2Args(%+v)", *p)
}

var fieldIDToName_MyServiceM2Args = map[int16]string{
	1: "p2",
}

type MyServiceM2Result struct {
	Success *string `thrift:"success,0,optional" json:"success,omitempty"`
}

func NewMyServiceM2Result() *MyServiceM2Result {
	return &MyServiceM2Result{}
}

func (p *MyServiceM2Result) InitDefault() {
}

var MyServiceM2Result_Success_DEFAULT string

func (p *MyServiceM2Result) GetSuccess() (v string) {
	if !p.IsSetSuccess() {
		return MyServiceM2Result_Success_DEFAULT
	}
	return *p.Success
}

func (p *MyServiceM2Result) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *MyServiceM2Result) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyServiceM2Result(%+v)", *p)
}

var fieldIDToName_MyServiceM2Result = map[int16]string{
	0: "success",
}

type MyServiceM3Args struct {
	A0 *A0 `thrift:"a0,1,required" json:"a0"`
	A3 *A3 `thrift:"a3,2,required" json:"a3"`
}

func NewMyServiceM3Args() *MyServiceM3Args {
	return &MyServiceM3Args{}
}

func (p *MyServiceM3Args) InitDefault() {
}

var MyServiceM3Args_A0_DEFAULT *A0

func (p *MyServiceM3Args) GetA0() (v *A0) {
	if !p.IsSetA0() {
		return MyServiceM3Args_A0_DEFAULT
	}
	return p.A0
}

var MyServiceM3Args_A3_DEFAULT *A3

func (p *MyServiceM3Args) GetA3() (v *A3) {
	if !p.IsSetA3() {
		return MyServiceM3Args_A3_DEFAULT
	}
	return p.A3
}

func (p *MyServiceM3Args) IsSetA0() bool {
	return p.A0 != nil
}

func (p *MyServiceM3Args) IsSetA3() bool {
	return p.A3 != nil
}

func (p *MyServiceM3Args) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyServiceM3Args(%+v)", *p)
}

var fieldIDToName_MyServiceM3Args = map[int16]string{
	1: "a0",
	2: "a3",
}

type MyServiceM3Result struct {
	Success *A1 `thrift:"success,0,optional" json:"success,omitempty"`
}

func NewMyServiceM3Result() *MyServiceM3Result {
	return &MyServiceM3Result{}
}

func (p *MyServiceM3Result) InitDefault() {
}

var MyServiceM3Result_Success_DEFAULT *A1

func (p *MyServiceM3Result) GetSuccess() (v *A1) {
	if !p.IsSetSuccess() {
		return MyServiceM3Result_Success_DEFAULT
	}
	return p.Success
}

func (p *MyServiceM3Result) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *MyServiceM3Result) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyServiceM3Result(%+v)", *p)
}

var fieldIDToName_MyServiceM3Result = map[int16]string{
	0: "success",
}

type MyParentService interface {
	MyAnotherService

	M11(ctx context.Context) (r string, err error)

	M22(ctx context.Context) (r string, err error)
}

type MyParentServiceM11Args struct {
}

func NewMyParentServiceM11Args() *MyParentServiceM11Args {
	return &MyParentServiceM11Args{}
}

func (p *MyParentServiceM11Args) InitDefault() {
}

func (p *MyParentServiceM11Args) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyParentServiceM11Args(%+v)", *p)
}

var fieldIDToName_MyParentServiceM11Args = map[int16]string{}

type MyParentServiceM11Result struct {
	Success *string `thrift:"success,0,optional" json:"success,omitempty"`
}

func NewMyParentServiceM11Result() *MyParentServiceM11Result {
	return &MyParentServiceM11Result{}
}

func (p *MyParentServiceM11Result) InitDefault() {
}

var MyParentServiceM11Result_Success_DEFAULT string

func (p *MyParentServiceM11Result) GetSuccess() (v string) {
	if !p.IsSetSuccess() {
		return MyParentServiceM11Result_Success_DEFAULT
	}
	return *p.Success
}

func (p *MyParentServiceM11Result) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *MyParentServiceM11Result) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyParentServiceM11Result(%+v)", *p)
}

var fieldIDToName_MyParentServiceM11Result = map[int16]string{
	0: "success",
}

type MyParentServiceM22Args struct {
}

func NewMyParentServiceM22Args() *MyParentServiceM22Args {
	return &MyParentServiceM22Args{}
}

func (p *MyParentServiceM22Args) InitDefault() {
}

func (p *MyParentServiceM22Args) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyParentServiceM22Args(%+v)", *p)
}

var fieldIDToName_MyParentServiceM22Args = map[int16]string{}

type MyParentServiceM22Result struct {
	Success *string `thrift:"success,0,optional" json:"success,omitempty"`
}

func NewMyParentServiceM22Result() *MyParentServiceM22Result {
	return &MyParentServiceM22Result{}
}

func (p *MyParentServiceM22Result) InitDefault() {
}

var MyParentServiceM22Result_Success_DEFAULT string

func (p *MyParentServiceM22Result) GetSuccess() (v string) {
	if !p.IsSetSuccess() {
		return MyParentServiceM22Result_Success_DEFAULT
	}
	return *p.Success
}

func (p *MyParentServiceM22Result) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *MyParentServiceM22Result) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MyParentServiceM22Result(%+v)", *p)
}

var fieldIDToName_MyParentServiceM22Result = map[int16]string{
	0: "success",
}
