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

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

// Notice Notice provides a structure for presenting notifications in Grafana's user interface.
//
// swagger:model Notice
type Notice struct {

	// inspect
	Inspect InspectType `json:"inspect,omitempty"`

	// Link is an optional link for display in the user interface and can be an
	// absolute URL or a path relative to Grafana's root url.
	Link string `json:"link,omitempty"`

	// severity
	Severity NoticeSeverity `json:"severity,omitempty"`

	// Text is freeform descriptive text for the notice.
	Text string `json:"text,omitempty"`
}

// Validate validates this notice
func (m *Notice) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *Notice) validateInspect(formats strfmt.Registry) error {
	if swag.IsZero(m.Inspect) { // not required
		return nil
	}

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

	return nil
}

func (m *Notice) validateSeverity(formats strfmt.Registry) error {
	if swag.IsZero(m.Severity) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (m *Notice) contextValidateInspect(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *Notice) contextValidateSeverity(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

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

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