/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*
*  Licensed to Elasticsearch B.V. under one or more contributor
*  license agreements. See the NOTICE file distributed with
*  this work for additional information regarding copyright
*  ownership. Elasticsearch B.V. licenses this file to you under
*  the Apache License, Version 2.0 (the "License"); you may
*  not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
* 	http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing,
*  software distributed under the License is distributed on an
*  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
*  KIND, either express or implied.  See the License for the
*  specific language governing permissions and limitations
*  under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using OpenSearch.Net.Utf8Json;
namespace OpenSearch.Client.Specification.IngestApi
{
	[InterfaceDataContract]
	public interface IGrokProcessor : IProcessor
	{
		/// 
		/// The field to use for grok expression parsing
		/// 
		[DataMember(Name ="field")]
		Field Field { get; set; }
		/// 
		/// A map of pattern-name and pattern tuples defining custom patterns
		/// to be used by the current processor. Patterns matching existing
		/// names will override the pre-existing definition.
		/// 
		[DataMember(Name ="pattern_definitions")]
		IDictionary PatternDefinitions { get; set; }
		/// 
		/// An ordered list of grok expression to match and extract named captures with.
		/// Returns on the first expression in the list that matches.
		/// 
		[DataMember(Name ="patterns")]
		IEnumerable Patterns { get; set; }
		/// 
		/// when true, _ingest._grok_match_index will be inserted into your matched document’s
		/// metadata with the index into the pattern found in patterns that matched.
		/// 
		[DataMember(Name ="trace_match")]
		bool? TraceMatch { get; set; }
		/// 
		/// If true and  does not exist or is null,
		/// the processor quietly exits without modifying the document. Default is false
		/// 
		[DataMember(Name = "ignore_missing")]
		bool? IgnoreMissing { get; set; }
	}
	/// 
	public class GrokProcessor : ProcessorBase, IGrokProcessor
	{
		/// 
		public Field Field { get; set; }
		/// 
		public IDictionary PatternDefinitions { get; set; }
		/// 
		public IEnumerable Patterns { get; set; }
		/// 
		public bool? TraceMatch { get; set; }
		/// 
		public bool? IgnoreMissing { get; set; }
		protected override string Name => "grok";
	}
	/// 
	public class GrokProcessorDescriptor
		: ProcessorDescriptorBase, IGrokProcessor>, IGrokProcessor
		where T : class
	{
		protected override string Name => "grok";
		Field IGrokProcessor.Field { get; set; }
		IDictionary IGrokProcessor.PatternDefinitions { get; set; }
		IEnumerable IGrokProcessor.Patterns { get; set; }
		bool? IGrokProcessor.TraceMatch { get; set; }
		bool? IGrokProcessor.IgnoreMissing { get; set; }
		/// 
		public GrokProcessorDescriptor Field(Field field) => Assign(field, (a, v) => a.Field = v);
		/// 
		public GrokProcessorDescriptor Field(Expression> objectPath) =>
			Assign(objectPath, (a, v) => a.Field = v);
		/// 
		public GrokProcessorDescriptor Patterns(IEnumerable patterns) => Assign(patterns, (a, v) => a.Patterns = v);
		/// 
		public GrokProcessorDescriptor Patterns(params string[] patterns) => Assign(patterns, (a, v) => a.Patterns = v);
		/// 
		public GrokProcessorDescriptor PatternDefinitions(
			Func, FluentDictionary> patternDefinitions
		) =>
			Assign(patternDefinitions, (a, v) => a.PatternDefinitions = v?.Invoke(new FluentDictionary()));
		/// 
		public GrokProcessorDescriptor TraceMatch(bool? traceMatch = true) =>
			Assign(traceMatch, (a, v) => a.TraceMatch = v);
		/// 
		public GrokProcessorDescriptor IgnoreMissing(bool? ignoreMissing = true) => Assign(ignoreMissing, (a, v) => a.IgnoreMissing = v);
	}
}