// 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"
	"github.com/go-openapi/validate"
)

// CentralReplication central replication
//
// swagger:model centralReplication
type CentralReplication struct {

	// create progress
	CreateProgress *ClusterCreateProgress `json:"create_progress,omitempty"`

	// creation time
	// Format: date-time
	CreationTime strfmt.DateTime `json:"creation_time,omitempty"`

	// creator
	Creator string `json:"creator,omitempty"`

	// detach user
	DetachUser string `json:"detach_user,omitempty"`

	// detached time
	// Format: date-time
	DetachedTime strfmt.DateTime `json:"detached_time,omitempty"`

	// detached tso
	DetachedTso string `json:"detached_tso,omitempty"`

	// primary cluster id
	PrimaryClusterID string `json:"primary_cluster_id,omitempty"`

	// primary cluster name
	PrimaryClusterName string `json:"primary_cluster_name,omitempty"`

	// primary write status
	PrimaryWriteStatus *CentralWriteStatus `json:"primary_write_status,omitempty"`

	// replication id
	ReplicationID string `json:"replication_id,omitempty"`

	// replication lag
	ReplicationLag string `json:"replication_lag,omitempty"`

	// secondary cluster id
	SecondaryClusterID string `json:"secondary_cluster_id,omitempty"`

	// secondary cluster name
	SecondaryClusterName string `json:"secondary_cluster_name,omitempty"`

	// secondary write status
	SecondaryWriteStatus *CentralWriteStatus `json:"secondary_write_status,omitempty"`

	// status
	Status string `json:"status,omitempty"`
}

// Validate validates this central replication
func (m *CentralReplication) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

func (m *CentralReplication) validateCreateProgress(formats strfmt.Registry) error {
	if swag.IsZero(m.CreateProgress) { // not required
		return nil
	}

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

	return nil
}

func (m *CentralReplication) validateCreationTime(formats strfmt.Registry) error {
	if swag.IsZero(m.CreationTime) { // not required
		return nil
	}

	if err := validate.FormatOf("creation_time", "body", "date-time", m.CreationTime.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *CentralReplication) validateDetachedTime(formats strfmt.Registry) error {
	if swag.IsZero(m.DetachedTime) { // not required
		return nil
	}

	if err := validate.FormatOf("detached_time", "body", "date-time", m.DetachedTime.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *CentralReplication) validatePrimaryWriteStatus(formats strfmt.Registry) error {
	if swag.IsZero(m.PrimaryWriteStatus) { // not required
		return nil
	}

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

	return nil
}

func (m *CentralReplication) validateSecondaryWriteStatus(formats strfmt.Registry) error {
	if swag.IsZero(m.SecondaryWriteStatus) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

func (m *CentralReplication) contextValidateCreateProgress(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *CentralReplication) contextValidatePrimaryWriteStatus(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *CentralReplication) contextValidateSecondaryWriteStatus(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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