// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package log // import "go.opentelemetry.io/otel/sdk/log"

import (
	
	

	
	
)

// Compile-time check SimpleProcessor implements Processor.
var _ Processor = (*SimpleProcessor)(nil)

// SimpleProcessor is an processor that synchronously exports log records.
//
// Use [NewSimpleProcessor] to create a SimpleProcessor.
type SimpleProcessor struct {
	mu       sync.Mutex
	exporter Exporter
	inst     *observ.SLP
	noCmp    [0]func() //nolint: unused  // This is indeed used.
}

// NewSimpleProcessor is a simple Processor adapter.
//
// This Processor is not recommended for production use due to its synchronous
// nature, which makes it suitable for testing, debugging, or demonstrating
// other features, but can lead to slow performance and high computational
// overhead. For production environments, it is recommended to use
// [NewBatchProcessor] instead. However, there may be exceptions where certain
// [Exporter] implementations perform better with this Processor.
func ( Exporter,  ...SimpleProcessorOption) *SimpleProcessor {
	 := &SimpleProcessor{
		exporter: ,
	}
	var  error
	.inst,  = observ.NewSLP(observ.NextSimpleProcessorID())
	if  != nil {
		otel.Handle()
	}
	return 
}

var simpleProcRecordsPool = sync.Pool{
	New: func() any {
		 := make([]Record, 1)
		return &
	},
}

// Enabled returns true, indicating this Processor will process all records.
func (*SimpleProcessor) (context.Context, EnabledParameters) bool {
	return true
}

// OnEmit batches provided log record.
func ( *SimpleProcessor) ( context.Context,  *Record) ( error) {
	if .exporter == nil {
		return nil
	}

	.mu.Lock()
	defer .mu.Unlock()

	 := simpleProcRecordsPool.Get().(*[]Record)
	(*)[0] = *
	defer func() {
		simpleProcRecordsPool.Put()
	}()

	if .inst != nil {
		defer func() {
			.inst.LogProcessed(, )
		}()
	}
	return .exporter.Export(, *)
}

// Shutdown shuts down the exporter.
func ( *SimpleProcessor) ( context.Context) error {
	if .exporter == nil {
		return nil
	}

	return .exporter.Shutdown()
}

// ForceFlush flushes the exporter.
func ( *SimpleProcessor) ( context.Context) error {
	if .exporter == nil {
		return nil
	}

	return .exporter.ForceFlush()
}

// SimpleProcessorOption applies a configuration to a [SimpleProcessor].
type SimpleProcessorOption interface {
	apply()
}