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

package models

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

import (
	"context"
	stderrors "errors"

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

// PolicyServiceCreateRuleBody policy service create rule body
//
// swagger:model PolicyServiceCreateRuleBody
type PolicyServiceCreateRuleBody struct {

	// The action applied for the rule when calling the tasks
	Action *V1alpha1RuleAction `json:"action,omitempty"`

	// A human-readable description for the Rule.
	Description string `json:"description,omitempty"`

	// A human-readable name for the Rule.
	Name string `json:"name,omitempty"`

	// Need User Approval for this Rule.
	NeedsApproval bool `json:"needsApproval,omitempty"`

	// The tasks that this Rule applies to.
	Tasks []string `json:"tasks"`
}

// Validate validates this policy service create rule body
func (m *PolicyServiceCreateRuleBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *PolicyServiceCreateRuleBody) validateAction(formats strfmt.Registry) error {
	if swag.IsZero(m.Action) { // not required
		return nil
	}

	if m.Action != nil {
		if err := m.Action.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("action")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("action")
			}

			return err
		}
	}

	return nil
}

// ContextValidate validate this policy service create rule body based on the context it is used
func (m *PolicyServiceCreateRuleBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *PolicyServiceCreateRuleBody) contextValidateAction(ctx context.Context, formats strfmt.Registry) error {

	if m.Action != nil {

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

		if err := m.Action.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("action")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("action")
			}

			return err
		}
	}

	return nil
}

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

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