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

// RepoCommit RepoCommit contains information of a commit in the context of a repository.
//
// swagger:model RepoCommit
type RepoCommit struct {

	// message
	Message string `json:"message,omitempty"`

	// URL
	URL string `json:"url,omitempty"`

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

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

	// tree
	Tree *CommitMeta `json:"tree,omitempty"`

	// verification
	Verification *PayloadCommitVerification `json:"verification,omitempty"`
}

// Validate validates this repo commit
func (m *RepoCommit) Validate(formats strfmt.Registry) error {
	var res []error

	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.validateTree(formats); err != nil {
		res = append(res, err)
	}

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

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

func (m *RepoCommit) 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 *RepoCommit) 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 *RepoCommit) validateTree(formats strfmt.Registry) error {
	if swag.IsZero(m.Tree) { // not required
		return nil
	}

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

	return nil
}

func (m *RepoCommit) validateVerification(formats strfmt.Registry) error {
	if swag.IsZero(m.Verification) { // not required
		return nil
	}

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

	return nil
}

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

	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.contextValidateTree(ctx, formats); err != nil {
		res = append(res, err)
	}

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

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

func (m *RepoCommit) 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 *RepoCommit) 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 *RepoCommit) contextValidateTree(ctx context.Context, formats strfmt.Registry) error {

	if m.Tree != nil {

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

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

	return nil
}

func (m *RepoCommit) contextValidateVerification(ctx context.Context, formats strfmt.Registry) error {

	if m.Verification != nil {

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

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

	return nil
}

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

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