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

// EntityApprovalTask entity approval task
//
// swagger:model entity.ApprovalTask
type EntityApprovalTask struct {

	// end at
	EndAt int64 `json:"end_at,omitempty"`

	// id
	ID int64 `json:"id,omitempty"`

	// notify lark type
	NotifyLarkType EntityLarkType `json:"notify_lark_type,omitempty"`

	// notify message id
	NotifyMessageID string `json:"notify_message_id,omitempty"`

	// start at
	StartAt int64 `json:"start_at,omitempty"`

	// status
	Status EntityApprovalTaskStatus `json:"status,omitempty"`

	// email
	UserEmail string `json:"user_email,omitempty"`
}

// Validate validates this entity approval task
func (m *EntityApprovalTask) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *EntityApprovalTask) validateNotifyLarkType(formats strfmt.Registry) error {
	if swag.IsZero(m.NotifyLarkType) { // not required
		return nil
	}

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

	return nil
}

func (m *EntityApprovalTask) validateStatus(formats strfmt.Registry) error {
	if swag.IsZero(m.Status) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (m *EntityApprovalTask) contextValidateNotifyLarkType(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *EntityApprovalTask) contextValidateStatus(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

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

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