// 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"
)

// OperationOperationApprover operation operation approver
//
// swagger:model operation.OperationApprover
type OperationOperationApprover struct {

	// The applicant leader is approver
	ApplicantLeader bool `json:"applicant_leader,omitempty"`

	// Emails of approvers
	Emails []string `json:"emails"`

	// from param
	FromParam *OperationOperationApproverFromParam `json:"from_param,omitempty"`

	// User group of approvers, defined in user service
	UserGroup string `json:"user_group,omitempty"`
}

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

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

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

func (m *OperationOperationApprover) validateFromParam(formats strfmt.Registry) error {
	if swag.IsZero(m.FromParam) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *OperationOperationApprover) contextValidateFromParam(ctx context.Context, formats strfmt.Registry) error {

	if m.FromParam != nil {

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

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

	return nil
}

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

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