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

package test

import "encoding/json"
import "fmt"
import yaml "gopkg.in/yaml.v3"

type IntegerDefault struct {
	// Count corresponds to the JSON schema field "count".
	Count int `json:"count" yaml:"count" mapstructure:"count"`

	// NullableCount corresponds to the JSON schema field "nullableCount".
	NullableCount IntegerDefaultNullableCount `json:"nullableCount" yaml:"nullableCount" mapstructure:"nullableCount"`

	// ProgramId corresponds to the JSON schema field "programId".
	ProgramId int `json:"programId" yaml:"programId" mapstructure:"programId"`
}

type IntegerDefaultNullableCount *int

// UnmarshalJSON implements json.Unmarshaler.
func (j *IntegerDefault) UnmarshalJSON(value []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(value, &raw); err != nil {
		return err
	}
	if _, ok := raw["count"]; raw != nil && !ok {
		return fmt.Errorf("field count in IntegerDefault: required")
	}
	if _, ok := raw["nullableCount"]; raw != nil && !ok {
		return fmt.Errorf("field nullableCount in IntegerDefault: required")
	}
	if _, ok := raw["programId"]; raw != nil && !ok {
		return fmt.Errorf("field programId in IntegerDefault: required")
	}
	type Plain IntegerDefault
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	if v, ok := raw["count"]; !ok || v == nil {
		plain.Count = 42
	}
	if v, ok := raw["nullableCount"]; !ok || v == nil {
		defaultInt := 0
		plain.NullableCount = &defaultInt

	}
	if v, ok := raw["programId"]; !ok || v == nil {
		plain.ProgramId = 0
	}
	*j = IntegerDefault(plain)
	return nil
}

// UnmarshalYAML implements yaml.Unmarshaler.
func (j *IntegerDefault) UnmarshalYAML(value *yaml.Node) error {
	var raw map[string]interface{}
	if err := value.Decode(&raw); err != nil {
		return err
	}
	if _, ok := raw["count"]; raw != nil && !ok {
		return fmt.Errorf("field count in IntegerDefault: required")
	}
	if _, ok := raw["nullableCount"]; raw != nil && !ok {
		return fmt.Errorf("field nullableCount in IntegerDefault: required")
	}
	if _, ok := raw["programId"]; raw != nil && !ok {
		return fmt.Errorf("field programId in IntegerDefault: required")
	}
	type Plain IntegerDefault
	var plain Plain
	if err := value.Decode(&plain); err != nil {
		return err
	}
	if v, ok := raw["count"]; !ok || v == nil {
		plain.Count = 42
	}
	if v, ok := raw["nullableCount"]; !ok || v == nil {
		defaultInt := 0
		plain.NullableCount = &defaultInt

	}
	if v, ok := raw["programId"]; !ok || v == nil {
		plain.ProgramId = 0
	}
	*j = IntegerDefault(plain)
	return nil
}
