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

// ChangeUserPasswordCommand change user password command
//
// swagger:model ChangeUserPasswordCommand
type ChangeUserPasswordCommand struct {

	// new password
	NewPassword Password `json:"newPassword,omitempty"`

	// old password
	OldPassword Password `json:"oldPassword,omitempty"`
}

// Validate validates this change user password command
func (m *ChangeUserPasswordCommand) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *ChangeUserPasswordCommand) validateNewPassword(formats strfmt.Registry) error {
	if swag.IsZero(m.NewPassword) { // not required
		return nil
	}

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

	return nil
}

func (m *ChangeUserPasswordCommand) validateOldPassword(formats strfmt.Registry) error {
	if swag.IsZero(m.OldPassword) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (m *ChangeUserPasswordCommand) contextValidateNewPassword(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *ChangeUserPasswordCommand) contextValidateOldPassword(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

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

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