// Code generated by ogen, DO NOT EDIT.

package gsn

import (
	"time"

	"github.com/go-faster/errors"

	"github.com/ogen-go/ogen/conv"
	"github.com/ogen-go/ogen/uri"
)

// EncodeURI encodes PredictionParameters as URI form.
func (s *PredictionParameters) EncodeURI(e uri.Encoder) error {
	if err := e.EncodeField("launch_latitude", func(e uri.Encoder) error {
		if val, ok := s.LaunchLatitude.Get(); ok {
			return e.EncodeValue(conv.Float64ToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"launch_latitude\"")
	}
	if err := e.EncodeField("launch_longitude", func(e uri.Encoder) error {
		if val, ok := s.LaunchLongitude.Get(); ok {
			return e.EncodeValue(conv.Float64ToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"launch_longitude\"")
	}
	if err := e.EncodeField("launch_datetime", func(e uri.Encoder) error {
		if val, ok := s.LaunchDatetime.Get(); ok {
			return e.EncodeValue(conv.DateTimeToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"launch_datetime\"")
	}
	if err := e.EncodeField("launch_altitude", func(e uri.Encoder) error {
		if val, ok := s.LaunchAltitude.Get(); ok {
			return e.EncodeValue(conv.Float64ToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"launch_altitude\"")
	}
	if err := e.EncodeField("profile", func(e uri.Encoder) error {
		if val, ok := s.Profile.Get(); ok {
			return e.EncodeValue(conv.StringToString(string(val)))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"profile\"")
	}
	if err := e.EncodeField("ascent_rate", func(e uri.Encoder) error {
		if val, ok := s.AscentRate.Get(); ok {
			return e.EncodeValue(conv.Float64ToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"ascent_rate\"")
	}
	if err := e.EncodeField("burst_altitude", func(e uri.Encoder) error {
		if val, ok := s.BurstAltitude.Get(); ok {
			return e.EncodeValue(conv.Float64ToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"burst_altitude\"")
	}
	if err := e.EncodeField("descent_rate", func(e uri.Encoder) error {
		if val, ok := s.DescentRate.Get(); ok {
			return e.EncodeValue(conv.Float64ToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"descent_rate\"")
	}
	if err := e.EncodeField("float_altitude", func(e uri.Encoder) error {
		if val, ok := s.FloatAltitude.Get(); ok {
			return e.EncodeValue(conv.Float64ToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"float_altitude\"")
	}
	if err := e.EncodeField("stop_datetime", func(e uri.Encoder) error {
		if val, ok := s.StopDatetime.Get(); ok {
			return e.EncodeValue(conv.DateTimeToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"stop_datetime\"")
	}
	if err := e.EncodeField("ascent_curve", func(e uri.Encoder) error {
		if val, ok := s.AscentCurve.Get(); ok {
			return e.EncodeValue(conv.StringToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"ascent_curve\"")
	}
	if err := e.EncodeField("descent_curve", func(e uri.Encoder) error {
		if val, ok := s.DescentCurve.Get(); ok {
			return e.EncodeValue(conv.StringToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"descent_curve\"")
	}
	if err := e.EncodeField("interpolate", func(e uri.Encoder) error {
		if val, ok := s.Interpolate.Get(); ok {
			return e.EncodeValue(conv.BoolToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"interpolate\"")
	}
	if err := e.EncodeField("format", func(e uri.Encoder) error {
		if val, ok := s.Format.Get(); ok {
			return e.EncodeValue(conv.StringToString(string(val)))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"format\"")
	}
	if err := e.EncodeField("dataset", func(e uri.Encoder) error {
		if val, ok := s.Dataset.Get(); ok {
			return e.EncodeValue(conv.DateTimeToString(val))
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "encode field \"dataset\"")
	}
	return nil
}

var uriFieldsNameOfPredictionParameters = [15]string{
	0:  "launch_latitude",
	1:  "launch_longitude",
	2:  "launch_datetime",
	3:  "launch_altitude",
	4:  "profile",
	5:  "ascent_rate",
	6:  "burst_altitude",
	7:  "descent_rate",
	8:  "float_altitude",
	9:  "stop_datetime",
	10: "ascent_curve",
	11: "descent_curve",
	12: "interpolate",
	13: "format",
	14: "dataset",
}

// DecodeURI decodes PredictionParameters from URI form.
func (s *PredictionParameters) DecodeURI(d uri.Decoder) error {
	if s == nil {
		return errors.New("invalid: unable to decode PredictionParameters to nil")
	}
	s.setDefaults()

	if err := d.DecodeFields(func(k string, d uri.Decoder) error {
		switch k {
		case "launch_latitude":
			if err := func() error {
				var sDotLaunchLatitudeVal float64
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToFloat64(val)
					if err != nil {
						return err
					}

					sDotLaunchLatitudeVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.LaunchLatitude.SetTo(sDotLaunchLatitudeVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"launch_latitude\"")
			}
		case "launch_longitude":
			if err := func() error {
				var sDotLaunchLongitudeVal float64
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToFloat64(val)
					if err != nil {
						return err
					}

					sDotLaunchLongitudeVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.LaunchLongitude.SetTo(sDotLaunchLongitudeVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"launch_longitude\"")
			}
		case "launch_datetime":
			if err := func() error {
				var sDotLaunchDatetimeVal time.Time
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToDateTime(val)
					if err != nil {
						return err
					}

					sDotLaunchDatetimeVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.LaunchDatetime.SetTo(sDotLaunchDatetimeVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"launch_datetime\"")
			}
		case "launch_altitude":
			if err := func() error {
				var sDotLaunchAltitudeVal float64
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToFloat64(val)
					if err != nil {
						return err
					}

					sDotLaunchAltitudeVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.LaunchAltitude.SetTo(sDotLaunchAltitudeVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"launch_altitude\"")
			}
		case "profile":
			if err := func() error {
				var sDotProfileVal PredictionParametersProfile
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToString(val)
					if err != nil {
						return err
					}

					sDotProfileVal = PredictionParametersProfile(c)
					return nil
				}(); err != nil {
					return err
				}
				s.Profile.SetTo(sDotProfileVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"profile\"")
			}
		case "ascent_rate":
			if err := func() error {
				var sDotAscentRateVal float64
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToFloat64(val)
					if err != nil {
						return err
					}

					sDotAscentRateVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.AscentRate.SetTo(sDotAscentRateVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"ascent_rate\"")
			}
		case "burst_altitude":
			if err := func() error {
				var sDotBurstAltitudeVal float64
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToFloat64(val)
					if err != nil {
						return err
					}

					sDotBurstAltitudeVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.BurstAltitude.SetTo(sDotBurstAltitudeVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"burst_altitude\"")
			}
		case "descent_rate":
			if err := func() error {
				var sDotDescentRateVal float64
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToFloat64(val)
					if err != nil {
						return err
					}

					sDotDescentRateVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.DescentRate.SetTo(sDotDescentRateVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"descent_rate\"")
			}
		case "float_altitude":
			if err := func() error {
				var sDotFloatAltitudeVal float64
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToFloat64(val)
					if err != nil {
						return err
					}

					sDotFloatAltitudeVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.FloatAltitude.SetTo(sDotFloatAltitudeVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"float_altitude\"")
			}
		case "stop_datetime":
			if err := func() error {
				var sDotStopDatetimeVal time.Time
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToDateTime(val)
					if err != nil {
						return err
					}

					sDotStopDatetimeVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.StopDatetime.SetTo(sDotStopDatetimeVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"stop_datetime\"")
			}
		case "ascent_curve":
			if err := func() error {
				var sDotAscentCurveVal string
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToString(val)
					if err != nil {
						return err
					}

					sDotAscentCurveVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.AscentCurve.SetTo(sDotAscentCurveVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"ascent_curve\"")
			}
		case "descent_curve":
			if err := func() error {
				var sDotDescentCurveVal string
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToString(val)
					if err != nil {
						return err
					}

					sDotDescentCurveVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.DescentCurve.SetTo(sDotDescentCurveVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"descent_curve\"")
			}
		case "interpolate":
			if err := func() error {
				var sDotInterpolateVal bool
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToBool(val)
					if err != nil {
						return err
					}

					sDotInterpolateVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.Interpolate.SetTo(sDotInterpolateVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"interpolate\"")
			}
		case "format":
			if err := func() error {
				var sDotFormatVal PredictionParametersFormat
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToString(val)
					if err != nil {
						return err
					}

					sDotFormatVal = PredictionParametersFormat(c)
					return nil
				}(); err != nil {
					return err
				}
				s.Format.SetTo(sDotFormatVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"format\"")
			}
		case "dataset":
			if err := func() error {
				var sDotDatasetVal time.Time
				if err := func() error {
					val, err := d.DecodeValue()
					if err != nil {
						return err
					}

					c, err := conv.ToDateTime(val)
					if err != nil {
						return err
					}

					sDotDatasetVal = c
					return nil
				}(); err != nil {
					return err
				}
				s.Dataset.SetTo(sDotDatasetVal)
				return nil
			}(); err != nil {
				return errors.Wrap(err, "decode field \"dataset\"")
			}
		default:
			return nil
		}
		return nil
	}); err != nil {
		return errors.Wrap(err, "decode PredictionParameters")
	}

	return nil
}
