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

// (c) 2012-2023 by Vernon Keenan
// All rights reserved worldwide.
// Proprietary product; unlicensed use is not allowed

package members_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"
)

// EmailMessage email message
//
// swagger:model emailMessage
type EmailMessage struct {

	// b c c address
	BCCAddress *string `json:"BCCAddress,omitempty"`

	// c c address
	CCAddress *string `json:"CCAddress,omitempty"`

	// created by ID
	CreatedByID *string `json:"CreatedByID,omitempty"`

	// created date
	CreatedDate *string `json:"CreatedDate,omitempty"`

	// from address
	FromAddress *string `json:"FromAddress,omitempty"`

	// from name
	FromName *string `json:"FromName,omitempty"`

	// HTML
	HTML *string `json:"HTML,omitempty"`

	// has attachment
	HasAttachment *bool `json:"HasAttachment,omitempty"`

	// headers
	Headers *Headers `json:"Headers,omitempty"`

	// ID
	ID string `json:"ID,omitempty"`

	// incoming
	Incoming *bool `json:"Incoming,omitempty"`

	// last modified by ID
	LastModifiedByID *string `json:"LastModifiedByID,omitempty"`

	// last modified date
	LastModifiedDate *string `json:"LastModifiedDate,omitempty"`

	// message date
	MessageDate *string `json:"MessageDate,omitempty"`

	// message identifier
	MessageIdentifier *string `json:"MessageIdentifier,omitempty"`

	// outgoing email ID
	OutgoingEmailID *string `json:"OutgoingEmailID,omitempty"`

	// reply to email message ID
	ReplyToEmailMessageID *string `json:"ReplyToEmailMessageID,omitempty"`

	// status
	Status *string `json:"Status,omitempty"`

	// subject
	Subject *string `json:"Subject,omitempty"`

	// text body
	TextBody *string `json:"TextBody,omitempty"`

	// thread identifier
	ThreadIdentifier *string `json:"ThreadIdentifier,omitempty"`

	// to address
	ToAddress *string `json:"ToAddress,omitempty"`

	// to name
	ToName *string `json:"ToName,omitempty"`
}

// Validate validates this email message
func (m *EmailMessage) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *EmailMessage) validateHeaders(formats strfmt.Registry) error {
	if swag.IsZero(m.Headers) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *EmailMessage) contextValidateHeaders(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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