// Code generated by go-swagger; DO NOT EDIT.

package ops

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
)

// ApprovalGetApprovalResp approval get approval resp
//
// swagger:model approval.GetApprovalResp
type ApprovalGetApprovalResp struct {

	// approval
	Approval *EntityApproval `json:"approval,omitempty"`

	// errcode
	Errcode APIErrCode `json:"errcode,omitempty"`

	// errmsg
	Errmsg string `json:"errmsg,omitempty"`

	// trace id
	TraceID string `json:"trace_id,omitempty"`
}

// Validate validates this approval get approval resp
func (m *ApprovalGetApprovalResp) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateApproval(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateErrcode(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *ApprovalGetApprovalResp) validateApproval(formats strfmt.Registry) error {
	if swag.IsZero(m.Approval) { // not required
		return nil
	}

	if m.Approval != nil {
		if err := m.Approval.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("approval")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("approval")
			}
			return err
		}
	}

	return nil
}

func (m *ApprovalGetApprovalResp) validateErrcode(formats strfmt.Registry) error {
	if swag.IsZero(m.Errcode) { // not required
		return nil
	}

	if err := m.Errcode.Validate(formats); err != nil {
		if ve, ok := err.(*errors.Validation); ok {
			return ve.ValidateName("errcode")
		} else if ce, ok := err.(*errors.CompositeError); ok {
			return ce.ValidateName("errcode")
		}
		return err
	}

	return nil
}

// ContextValidate validate this approval get approval resp based on the context it is used
func (m *ApprovalGetApprovalResp) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	if err := m.contextValidateApproval(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateErrcode(ctx, formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *ApprovalGetApprovalResp) contextValidateApproval(ctx context.Context, formats strfmt.Registry) error {

	if m.Approval != nil {

		if swag.IsZero(m.Approval) { // not required
			return nil
		}

		if err := m.Approval.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("approval")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("approval")
			}
			return err
		}
	}

	return nil
}

func (m *ApprovalGetApprovalResp) contextValidateErrcode(ctx context.Context, formats strfmt.Registry) error {

	if swag.IsZero(m.Errcode) { // not required
		return nil
	}

	if err := m.Errcode.ContextValidate(ctx, formats); err != nil {
		if ve, ok := err.(*errors.Validation); ok {
			return ve.ValidateName("errcode")
		} else if ce, ok := err.(*errors.CompositeError); ok {
			return ce.ValidateName("errcode")
		}
		return err
	}

	return nil
}

// MarshalBinary interface implementation
func (m *ApprovalGetApprovalResp) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation
func (m *ApprovalGetApprovalResp) UnmarshalBinary(b []byte) error {
	var res ApprovalGetApprovalResp
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
