// Code generated by Fern. DO NOT EDIT.

package jobs

import (
	json "encoding/json"
	fmt "fmt"
	management "github.com/auth0/go-auth0/v2/management"
)

type ErrorsGetResponse struct {
	GetJobErrorResponseContentList    []*management.GetJobErrorResponseContent
	GetJobGenericErrorResponseContent *management.GetJobGenericErrorResponseContent

	typ string
}

func (e *ErrorsGetResponse) GetGetJobErrorResponseContentList() []*management.GetJobErrorResponseContent {
	if e == nil {
		return nil
	}
	return e.GetJobErrorResponseContentList
}

func (e *ErrorsGetResponse) GetGetJobGenericErrorResponseContent() *management.GetJobGenericErrorResponseContent {
	if e == nil {
		return nil
	}
	return e.GetJobGenericErrorResponseContent
}

func (e *ErrorsGetResponse) UnmarshalJSON(data []byte) error {
	var valueGetJobErrorResponseContentList []*management.GetJobErrorResponseContent
	if err := json.Unmarshal(data, &valueGetJobErrorResponseContentList); err == nil {
		e.typ = "GetJobErrorResponseContentList"
		e.GetJobErrorResponseContentList = valueGetJobErrorResponseContentList
		return nil
	}
	valueGetJobGenericErrorResponseContent := new(management.GetJobGenericErrorResponseContent)
	if err := json.Unmarshal(data, &valueGetJobGenericErrorResponseContent); err == nil {
		e.typ = "GetJobGenericErrorResponseContent"
		e.GetJobGenericErrorResponseContent = valueGetJobGenericErrorResponseContent
		return nil
	}
	return fmt.Errorf("%s cannot be deserialized as a %T", data, e)
}

func (e ErrorsGetResponse) MarshalJSON() ([]byte, error) {
	if e.typ == "GetJobErrorResponseContentList" || e.GetJobErrorResponseContentList != nil {
		return json.Marshal(e.GetJobErrorResponseContentList)
	}
	if e.typ == "GetJobGenericErrorResponseContent" || e.GetJobGenericErrorResponseContent != nil {
		return json.Marshal(e.GetJobGenericErrorResponseContent)
	}
	return nil, fmt.Errorf("type %T does not include a non-empty union type", e)
}

type ErrorsGetResponseVisitor interface {
	VisitGetJobErrorResponseContentList([]*management.GetJobErrorResponseContent) error
	VisitGetJobGenericErrorResponseContent(*management.GetJobGenericErrorResponseContent) error
}

func (e *ErrorsGetResponse) Accept(visitor ErrorsGetResponseVisitor) error {
	if e.typ == "GetJobErrorResponseContentList" || e.GetJobErrorResponseContentList != nil {
		return visitor.VisitGetJobErrorResponseContentList(e.GetJobErrorResponseContentList)
	}
	if e.typ == "GetJobGenericErrorResponseContent" || e.GetJobGenericErrorResponseContent != nil {
		return visitor.VisitGetJobGenericErrorResponseContent(e.GetJobGenericErrorResponseContent)
	}
	return fmt.Errorf("type %T does not include a non-empty union type", e)
}
