// 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"
	"github.com/go-openapi/validate"
)

// OperationOperationApproverForParam operation operation approver for param
//
// swagger:model operation.OperationApproverForParam
type OperationOperationApproverForParam struct {

	// param name
	ParamName *OperationOperationApproverForParamParamName `json:"param_name,omitempty"`

	// The value of param to approver
	ParamValueMapping map[string]OperationOperationApprover `json:"param_value_mapping,omitempty"`
}

// Validate validates this operation operation approver for param
func (m *OperationOperationApproverForParam) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *OperationOperationApproverForParam) validateParamName(formats strfmt.Registry) error {
	if swag.IsZero(m.ParamName) { // not required
		return nil
	}

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

	return nil
}

func (m *OperationOperationApproverForParam) validateParamValueMapping(formats strfmt.Registry) error {
	if swag.IsZero(m.ParamValueMapping) { // not required
		return nil
	}

	for k := range m.ParamValueMapping {

		if err := validate.Required("param_value_mapping"+"."+k, "body", m.ParamValueMapping[k]); err != nil {
			return err
		}
		if val, ok := m.ParamValueMapping[k]; ok {
			if err := val.Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("param_value_mapping" + "." + k)
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("param_value_mapping" + "." + k)
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this operation operation approver for param based on the context it is used
func (m *OperationOperationApproverForParam) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *OperationOperationApproverForParam) contextValidateParamName(ctx context.Context, formats strfmt.Registry) error {

	if m.ParamName != nil {

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

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

	return nil
}

func (m *OperationOperationApproverForParam) contextValidateParamValueMapping(ctx context.Context, formats strfmt.Registry) error {

	for k := range m.ParamValueMapping {

		if val, ok := m.ParamValueMapping[k]; ok {
			if err := val.ContextValidate(ctx, formats); err != nil {
				return err
			}
		}

	}

	return nil
}

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

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