// Code generated by go-swagger; DO NOT EDIT.

package models

import (
	"context"

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

// ExamplepbBook An example resource type from AIP-123 used to test the behavior described in
// the CreateBookRequest message.
//
// See: https://google.aip.dev/123
//
// swagger:model examplepbBook
type ExamplepbBook struct {

	// Output only. Creation time of the book.
	// Read Only: true
	// Format: date-time
	CreateTime strfmt.DateTime `json:"createTime,omitempty"`

	// Output only. The book's ID.
	// Read Only: true
	ID string `json:"id,omitempty"`

	// The resource name of the book.
	//
	// Format: `publishers/{publisher}/books/{book}`
	//
	// Example: `publishers/1257894000000000000/books/my-book`
	Name string `json:"name,omitempty"`
}

// Validate validates this examplepb book
func (m *ExamplepbBook) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *ExamplepbBook) validateCreateTime(formats strfmt.Registry) error {
	if swag.IsZero(m.CreateTime) { // not required
		return nil
	}

	if err := validate.FormatOf("createTime", "body", "date-time", m.CreateTime.String(), formats); err != nil {
		return err
	}

	return nil
}

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

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

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

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

func (m *ExamplepbBook) contextValidateCreateTime(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "createTime", "body", m.CreateTime); err != nil {
		return err
	}

	return nil
}

func (m *ExamplepbBook) contextValidateID(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "id", "body", m.ID); err != nil {
		return err
	}

	return nil
}

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

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