// Code generated by Microsoft Kiota - DO NOT EDIT.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

package odataerrors

import (
	i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91 "github.com/microsoft/kiota-abstractions-go/serialization"
	ie8677ce2c7e1b4c22e9c3827ecd078d41185424dd9eeb92b7d971ed2d49a392e "github.com/microsoft/kiota-abstractions-go/store"
)

type MainError struct {
	// Stores model information.
	backingStore ie8677ce2c7e1b4c22e9c3827ecd078d41185424dd9eeb92b7d971ed2d49a392e.BackingStore
}

// NewMainError instantiates a new MainError and sets the default values.
func NewMainError() *MainError {
	m := &MainError{}
	m.backingStore = ie8677ce2c7e1b4c22e9c3827ecd078d41185424dd9eeb92b7d971ed2d49a392e.BackingStoreFactoryInstance()
	return m
}

// CreateMainErrorFromDiscriminatorValue creates a new instance of the appropriate class based on discriminator value
// returns a Parsable when successful
func CreateMainErrorFromDiscriminatorValue(parseNode i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) (i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable, error) {
	return NewMainError(), nil
}

// GetBackingStore gets the BackingStore property value. Stores model information.
// returns a BackingStore when successful
func (m *MainError) GetBackingStore() ie8677ce2c7e1b4c22e9c3827ecd078d41185424dd9eeb92b7d971ed2d49a392e.BackingStore {
	return m.backingStore
}

// GetCode gets the code property value. The code property
// returns a *string when successful
func (m *MainError) GetCode() *string {
	val, err := m.GetBackingStore().Get("code")
	if err != nil {
		panic(err)
	}
	if val != nil {
		return val.(*string)
	}
	return nil
}

// GetDetails gets the details property value. The details property
// returns a []ErrorDetailsable when successful
func (m *MainError) GetDetails() []ErrorDetailsable {
	val, err := m.GetBackingStore().Get("details")
	if err != nil {
		panic(err)
	}
	if val != nil {
		return val.([]ErrorDetailsable)
	}
	return nil
}

// GetFieldDeserializers the deserialization information for the current model
// returns a map[string]func(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode)(error) when successful
func (m *MainError) GetFieldDeserializers() map[string]func(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
	res := make(map[string]func(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error)
	res["code"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
		val, err := n.GetStringValue()
		if err != nil {
			return err
		}
		if val != nil {
			m.SetCode(val)
		}
		return nil
	}
	res["details"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
		val, err := n.GetCollectionOfObjectValues(CreateErrorDetailsFromDiscriminatorValue)
		if err != nil {
			return err
		}
		if val != nil {
			res := make([]ErrorDetailsable, len(val))
			for i, v := range val {
				if v != nil {
					res[i] = v.(ErrorDetailsable)
				}
			}
			m.SetDetails(res)
		}
		return nil
	}
	res["innerError"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
		val, err := n.GetObjectValue(CreateInnerErrorFromDiscriminatorValue)
		if err != nil {
			return err
		}
		if val != nil {
			m.SetInnerError(val.(InnerErrorable))
		}
		return nil
	}
	res["message"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
		val, err := n.GetStringValue()
		if err != nil {
			return err
		}
		if val != nil {
			m.SetMessage(val)
		}
		return nil
	}
	res["target"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
		val, err := n.GetStringValue()
		if err != nil {
			return err
		}
		if val != nil {
			m.SetTarget(val)
		}
		return nil
	}
	return res
}

// GetInnerError gets the innerError property value. The innerError property
// returns a InnerErrorable when successful
func (m *MainError) GetInnerError() InnerErrorable {
	val, err := m.GetBackingStore().Get("innerError")
	if err != nil {
		panic(err)
	}
	if val != nil {
		return val.(InnerErrorable)
	}
	return nil
}

// GetMessage gets the message property value. The message property
// returns a *string when successful
func (m *MainError) GetMessage() *string {
	val, err := m.GetBackingStore().Get("message")
	if err != nil {
		panic(err)
	}
	if val != nil {
		return val.(*string)
	}
	return nil
}

// GetTarget gets the target property value. The target property
// returns a *string when successful
func (m *MainError) GetTarget() *string {
	val, err := m.GetBackingStore().Get("target")
	if err != nil {
		panic(err)
	}
	if val != nil {
		return val.(*string)
	}
	return nil
}

// Serialize serializes information the current object
func (m *MainError) Serialize(writer i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.SerializationWriter) error {
	{
		err := writer.WriteStringValue("code", m.GetCode())
		if err != nil {
			return err
		}
	}
	if m.GetDetails() != nil {
		cast := make([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable, len(m.GetDetails()))
		for i, v := range m.GetDetails() {
			if v != nil {
				cast[i] = v.(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable)
			}
		}
		err := writer.WriteCollectionOfObjectValues("details", cast)
		if err != nil {
			return err
		}
	}
	{
		err := writer.WriteObjectValue("innerError", m.GetInnerError())
		if err != nil {
			return err
		}
	}
	{
		err := writer.WriteStringValue("message", m.GetMessage())
		if err != nil {
			return err
		}
	}
	{
		err := writer.WriteStringValue("target", m.GetTarget())
		if err != nil {
			return err
		}
	}
	return nil
}

// SetBackingStore sets the BackingStore property value. Stores model information.
func (m *MainError) SetBackingStore(value ie8677ce2c7e1b4c22e9c3827ecd078d41185424dd9eeb92b7d971ed2d49a392e.BackingStore) {
	m.backingStore = value
}

// SetCode sets the code property value. The code property
func (m *MainError) SetCode(value *string) {
	err := m.GetBackingStore().Set("code", value)
	if err != nil {
		panic(err)
	}
}

// SetDetails sets the details property value. The details property
func (m *MainError) SetDetails(value []ErrorDetailsable) {
	err := m.GetBackingStore().Set("details", value)
	if err != nil {
		panic(err)
	}
}

// SetInnerError sets the innerError property value. The innerError property
func (m *MainError) SetInnerError(value InnerErrorable) {
	err := m.GetBackingStore().Set("innerError", value)
	if err != nil {
		panic(err)
	}
}

// SetMessage sets the message property value. The message property
func (m *MainError) SetMessage(value *string) {
	err := m.GetBackingStore().Set("message", value)
	if err != nil {
		panic(err)
	}
}

// SetTarget sets the target property value. The target property
func (m *MainError) SetTarget(value *string) {
	err := m.GetBackingStore().Set("target", value)
	if err != nil {
		panic(err)
	}
}

type MainErrorable interface {
	ie8677ce2c7e1b4c22e9c3827ecd078d41185424dd9eeb92b7d971ed2d49a392e.BackedModel
	i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable
	GetBackingStore() ie8677ce2c7e1b4c22e9c3827ecd078d41185424dd9eeb92b7d971ed2d49a392e.BackingStore
	GetCode() *string
	GetDetails() []ErrorDetailsable
	GetInnerError() InnerErrorable
	GetMessage() *string
	GetTarget() *string
	SetBackingStore(value ie8677ce2c7e1b4c22e9c3827ecd078d41185424dd9eeb92b7d971ed2d49a392e.BackingStore)
	SetCode(value *string)
	SetDetails(value []ErrorDetailsable)
	SetInnerError(value InnerErrorable)
	SetMessage(value *string)
	SetTarget(value *string)
}
