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

// CloudconfigFileConfiguration cloudconfig file configuration
//
// swagger:model cloudconfig.FileConfiguration
type CloudconfigFileConfiguration struct {

	// key: parameter name
	AllParameters map[string]CloudconfigUnifiedParameter `json:"all_parameters,omitempty"`

	// belong to component
	BelongToComponent string `json:"belong_to_component,omitempty"`

	// config type
	ConfigType string `json:"config_type,omitempty"`

	// filename
	Filename string `json:"filename,omitempty"`

	// format
	Format string `json:"format,omitempty"`

	// template id
	TemplateID int64 `json:"template_id,omitempty"`

	// text
	Text string `json:"text,omitempty"`
}

// Validate validates this cloudconfig file configuration
func (m *CloudconfigFileConfiguration) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *CloudconfigFileConfiguration) validateAllParameters(formats strfmt.Registry) error {
	if swag.IsZero(m.AllParameters) { // not required
		return nil
	}

	for k := range m.AllParameters {

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

	}

	return nil
}

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

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

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

func (m *CloudconfigFileConfiguration) contextValidateAllParameters(ctx context.Context, formats strfmt.Registry) error {

	for k := range m.AllParameters {

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

	}

	return nil
}

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

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