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

// GithubGetPullRequestResp github get pull request resp
//
// swagger:model github.GetPullRequestResp
type GithubGetPullRequestResp struct {

	// errcode
	Errcode APIErrCode `json:"errcode,omitempty"`

	// errmsg
	Errmsg string `json:"errmsg,omitempty"`

	// pull request
	PullRequest *GithubPullRequest `json:"pull_request,omitempty"`

	// trace id
	TraceID string `json:"trace_id,omitempty"`
}

// Validate validates this github get pull request resp
func (m *GithubGetPullRequestResp) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *GithubGetPullRequestResp) validateErrcode(formats strfmt.Registry) error {
	if swag.IsZero(m.Errcode) { // not required
		return nil
	}

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

	return nil
}

func (m *GithubGetPullRequestResp) validatePullRequest(formats strfmt.Registry) error {
	if swag.IsZero(m.PullRequest) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this github get pull request resp based on the context it is used
func (m *GithubGetPullRequestResp) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *GithubGetPullRequestResp) contextValidateErrcode(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *GithubGetPullRequestResp) contextValidatePullRequest(ctx context.Context, formats strfmt.Registry) error {

	if m.PullRequest != nil {

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

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

	return nil
}

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

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