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

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

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

// LogFile log file
//
// swagger:model LogFile
type LogFile struct {

	// The file encoding: default | auto | UTF-8 | UTF-16
	Encoding string `json:"encoding,omitempty"`

	// The regex or plain text to look for in the file and not trigger alert if found
	Excludes []string `json:"excludes,omitempty"`

	// matches
	Matches []*MatchPattern `json:"matches,omitempty"`

	// The path of the log file to monitor
	Path string `json:"path,omitempty"`

	// Whether or not glob is used in the path
	UseGlob bool `json:"useGlob,omitempty"`
}

// Validate validates this log file
func (m *LogFile) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *LogFile) validateMatches(formats strfmt.Registry) error {
	if swag.IsZero(m.Matches) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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

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

func (m *LogFile) contextValidateMatches(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

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

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