// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT.

package test

import "encoding/json"
import "errors"
import "fmt"
import "github.com/go-viper/mapstructure/v2"
import yaml "gopkg.in/yaml.v3"
import "reflect"
import "strings"

type BaseObject struct {
	// BaseField corresponds to the JSON schema field "BaseField".
	BaseField string `json:"BaseField" yaml:"BaseField" mapstructure:"BaseField"`
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *BaseObject) UnmarshalJSON(value []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(value, &raw); err != nil {
		return err
	}
	if _, ok := raw["BaseField"]; raw != nil && !ok {
		return fmt.Errorf("field BaseField in BaseObject: required")
	}
	type Plain BaseObject
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	*j = BaseObject(plain)
	return nil
}

// UnmarshalYAML implements yaml.Unmarshaler.
func (j *BaseObject) UnmarshalYAML(value *yaml.Node) error {
	var raw map[string]interface{}
	if err := value.Decode(&raw); err != nil {
		return err
	}
	if _, ok := raw["BaseField"]; raw != nil && !ok {
		return fmt.Errorf("field BaseField in BaseObject: required")
	}
	type Plain BaseObject
	var plain Plain
	if err := value.Decode(&plain); err != nil {
		return err
	}
	*j = BaseObject(plain)
	return nil
}

type ComposedWithAllOfAndProperties_0 = BaseObject

type ComposedWithAllOfAndProperties struct {
	// BaseField corresponds to the JSON schema field "BaseField".
	BaseField string `json:"BaseField" yaml:"BaseField" mapstructure:"BaseField"`

	// DirectField corresponds to the JSON schema field "DirectField".
	DirectField []string `json:"DirectField,omitempty,omitzero" yaml:"DirectField,omitempty" mapstructure:"DirectField,omitempty"`

	AdditionalProperties interface{} `mapstructure:",remain"`
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ComposedWithAllOfAndProperties) UnmarshalJSON(value []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(value, &raw); err != nil {
		return err
	}
	var composedWithAllOfAndProperties_0 ComposedWithAllOfAndProperties_0
	var errs []error
	if err := composedWithAllOfAndProperties_0.UnmarshalJSON(value); err != nil {
		errs = append(errs, err)
	}
	if len(errs) == 1 {
		return fmt.Errorf("all validators failed: %s", errors.Join(errs...))
	}
	type Plain ComposedWithAllOfAndProperties
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	st := reflect.TypeOf(Plain{})
	for i := range st.NumField() {
		delete(raw, st.Field(i).Name)
		delete(raw, strings.Split(st.Field(i).Tag.Get("json"), ",")[0])
	}
	if err := mapstructure.Decode(raw, &plain.AdditionalProperties); err != nil {
		return err
	}
	*j = ComposedWithAllOfAndProperties(plain)
	return nil
}

// UnmarshalYAML implements yaml.Unmarshaler.
func (j *ComposedWithAllOfAndProperties) UnmarshalYAML(value *yaml.Node) error {
	var raw map[string]interface{}
	if err := value.Decode(&raw); err != nil {
		return err
	}
	var composedWithAllOfAndProperties_0 ComposedWithAllOfAndProperties_0
	var errs []error
	if err := composedWithAllOfAndProperties_0.UnmarshalYAML(value); err != nil {
		errs = append(errs, err)
	}
	if len(errs) == 1 {
		return fmt.Errorf("all validators failed: %s", errors.Join(errs...))
	}
	type Plain ComposedWithAllOfAndProperties
	var plain Plain
	if err := value.Decode(&plain); err != nil {
		return err
	}
	st := reflect.TypeOf(Plain{})
	for i := range st.NumField() {
		delete(raw, st.Field(i).Name)
		delete(raw, strings.Split(st.Field(i).Tag.Get("json"), ",")[0])
	}
	if err := mapstructure.Decode(raw, &plain.AdditionalProperties); err != nil {
		return err
	}
	*j = ComposedWithAllOfAndProperties(plain)
	return nil
}
