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

// EntityClusterMaintenance entity cluster maintenance
//
// swagger:model entity.ClusterMaintenance
type EntityClusterMaintenance struct {

	// id
	ID int64 `json:"id,omitempty"`

	// the id of MaintenanceTask in the core svc
	InstanceID int64 `json:"instance_id,omitempty"`

	// lark notified at
	LarkNotifiedAt string `json:"lark_notified_at,omitempty"`

	// task
	Task *EntityClusterMaintenanceTask `json:"task,omitempty"`
}

// Validate validates this entity cluster maintenance
func (m *EntityClusterMaintenance) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *EntityClusterMaintenance) validateTask(formats strfmt.Registry) error {
	if swag.IsZero(m.Task) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *EntityClusterMaintenance) contextValidateTask(ctx context.Context, formats strfmt.Registry) error {

	if m.Task != nil {

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

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

	return nil
}

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

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