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

// JumpAuthorization jump authorization
//
// swagger:model jump.Authorization
type JumpAuthorization struct {

	// email
	Applicant string `json:"applicant,omitempty"`

	// approval id
	ApprovalID int64 `json:"approval_id,omitempty"`

	// closed at
	ClosedAt int64 `json:"closed_at,omitempty"`

	// cluster deploy type
	ClusterDeployType JumpJumpClusterDeployType `json:"cluster_deploy_type,omitempty"`

	// cluster id
	ClusterID string `json:"cluster_id,omitempty"`

	// created at
	CreatedAt int64 `json:"created_at,omitempty"`

	// expiration
	Expiration JumpJumpExpiration `json:"expiration,omitempty"`

	// expire at
	ExpireAt int64 `json:"expire_at,omitempty"`

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

	// phase
	Phase *JumpAuthorizationPhase `json:"phase,omitempty"`

	// plane
	Plane JumpJumpPlane `json:"plane,omitempty"`

	// privilege
	Privilege JumpJumpPrivilege `json:"privilege,omitempty"`

	// reason
	Reason string `json:"reason,omitempty"`

	// jump token expire time, nil means no expire
	TokenRefreshAt int64 `json:"token_refresh_at,omitempty"`
}

// Validate validates this jump authorization
func (m *JumpAuthorization) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

func (m *JumpAuthorization) validateClusterDeployType(formats strfmt.Registry) error {
	if swag.IsZero(m.ClusterDeployType) { // not required
		return nil
	}

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

	return nil
}

func (m *JumpAuthorization) validateExpiration(formats strfmt.Registry) error {
	if swag.IsZero(m.Expiration) { // not required
		return nil
	}

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

	return nil
}

func (m *JumpAuthorization) validatePhase(formats strfmt.Registry) error {
	if swag.IsZero(m.Phase) { // not required
		return nil
	}

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

	return nil
}

func (m *JumpAuthorization) validatePlane(formats strfmt.Registry) error {
	if swag.IsZero(m.Plane) { // not required
		return nil
	}

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

	return nil
}

func (m *JumpAuthorization) validatePrivilege(formats strfmt.Registry) error {
	if swag.IsZero(m.Privilege) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

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

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

func (m *JumpAuthorization) contextValidateClusterDeployType(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *JumpAuthorization) contextValidateExpiration(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *JumpAuthorization) contextValidatePhase(ctx context.Context, formats strfmt.Registry) error {

	if m.Phase != nil {

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

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

	return nil
}

func (m *JumpAuthorization) contextValidatePlane(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *JumpAuthorization) contextValidatePrivilege(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

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

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