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

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
	"github.com/go-openapi/validate"
)

// ChangeFilesOptions ChangeFilesOptions options for creating, updating or deleting multiple files
// Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
//
// swagger:model ChangeFilesOptions
type ChangeFilesOptions struct {

	// branch (optional) to base this file from. if not given, the default branch is used
	BranchName string `json:"branch,omitempty"`

	// list of file operations
	// Required: true
	Files []*ChangeFileOperation `json:"files"`

	// message (optional) for the commit of this file. if not supplied, a default message will be used
	Message string `json:"message,omitempty"`

	// new_branch (optional) will make a new branch from `branch` before creating the file
	NewBranchName string `json:"new_branch,omitempty"`

	// Add a Signed-off-by trailer by the committer at the end of the commit log message.
	Signoff bool `json:"signoff,omitempty"`

	// author
	Author *Identity `json:"author,omitempty"`

	// committer
	Committer *Identity `json:"committer,omitempty"`

	// dates
	Dates *CommitDateOptions `json:"dates,omitempty"`
}

// Validate validates this change files options
func (m *ChangeFilesOptions) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *ChangeFilesOptions) validateFiles(formats strfmt.Registry) error {

	if err := validate.Required("files", "body", m.Files); err != nil {
		return err
	}

	for i := 0; i < len(m.Files); i++ {
		if swag.IsZero(m.Files[i]) { // not required
			continue
		}

		if m.Files[i] != nil {
			if err := m.Files[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("files" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("files" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *ChangeFilesOptions) validateAuthor(formats strfmt.Registry) error {
	if swag.IsZero(m.Author) { // not required
		return nil
	}

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

	return nil
}

func (m *ChangeFilesOptions) validateCommitter(formats strfmt.Registry) error {
	if swag.IsZero(m.Committer) { // not required
		return nil
	}

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

	return nil
}

func (m *ChangeFilesOptions) validateDates(formats strfmt.Registry) error {
	if swag.IsZero(m.Dates) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

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

func (m *ChangeFilesOptions) contextValidateFiles(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Files); i++ {

		if m.Files[i] != nil {

			if swag.IsZero(m.Files[i]) { // not required
				return nil
			}

			if err := m.Files[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("files" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("files" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *ChangeFilesOptions) contextValidateAuthor(ctx context.Context, formats strfmt.Registry) error {

	if m.Author != nil {

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

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

	return nil
}

func (m *ChangeFilesOptions) contextValidateCommitter(ctx context.Context, formats strfmt.Registry) error {

	if m.Committer != nil {

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

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

	return nil
}

func (m *ChangeFilesOptions) contextValidateDates(ctx context.Context, formats strfmt.Registry) error {

	if m.Dates != nil {

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

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

	return nil
}

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

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