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

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

// UserbehaviorEditSubscriptionReq userbehavior edit subscription req
//
// swagger:model userbehavior.EditSubscriptionReq
type UserbehaviorEditSubscriptionReq struct {

	// event type
	EventType UserbehaviorUBEventTp `json:"event_type,omitempty"`

	// lark chats
	LarkChats []*EntityLarkChatSimplified `json:"lark_chats"`

	// name
	Name string `json:"name,omitempty"`

	// selector
	Selector *UserbehaviorSelectorTp `json:"selector,omitempty"`

	// subscribe type
	SubscribeType UserbehaviorSubscribeTp `json:"subscribe_type,omitempty"`

	// template
	Template string `json:"template,omitempty"`
}

// Validate validates this userbehavior edit subscription req
func (m *UserbehaviorEditSubscriptionReq) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *UserbehaviorEditSubscriptionReq) validateEventType(formats strfmt.Registry) error {
	if swag.IsZero(m.EventType) { // not required
		return nil
	}

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

	return nil
}

func (m *UserbehaviorEditSubscriptionReq) validateLarkChats(formats strfmt.Registry) error {
	if swag.IsZero(m.LarkChats) { // not required
		return nil
	}

	for i := 0; i < len(m.LarkChats); i++ {
		if swag.IsZero(m.LarkChats[i]) { // not required
			continue
		}

		if m.LarkChats[i] != nil {
			if err := m.LarkChats[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("lark_chats" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("lark_chats" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *UserbehaviorEditSubscriptionReq) validateSelector(formats strfmt.Registry) error {
	if swag.IsZero(m.Selector) { // not required
		return nil
	}

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

	return nil
}

func (m *UserbehaviorEditSubscriptionReq) validateSubscribeType(formats strfmt.Registry) error {
	if swag.IsZero(m.SubscribeType) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this userbehavior edit subscription req based on the context it is used
func (m *UserbehaviorEditSubscriptionReq) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *UserbehaviorEditSubscriptionReq) contextValidateEventType(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *UserbehaviorEditSubscriptionReq) contextValidateLarkChats(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.LarkChats); i++ {

		if m.LarkChats[i] != nil {

			if swag.IsZero(m.LarkChats[i]) { // not required
				return nil
			}

			if err := m.LarkChats[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("lark_chats" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("lark_chats" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *UserbehaviorEditSubscriptionReq) contextValidateSelector(ctx context.Context, formats strfmt.Registry) error {

	if m.Selector != nil {

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

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

	return nil
}

func (m *UserbehaviorEditSubscriptionReq) contextValidateSubscribeType(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

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

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