package rcmgr

import (
	
	
	
)

// MetricsReporter is an interface for collecting metrics from resource manager actions
type MetricsReporter interface {
	// AllowConn is invoked when opening a connection is allowed
	AllowConn(dir network.Direction, usefd bool)
	// BlockConn is invoked when opening a connection is blocked
	BlockConn(dir network.Direction, usefd bool)

	// AllowStream is invoked when opening a stream is allowed
	AllowStream(p peer.ID, dir network.Direction)
	// BlockStream is invoked when opening a stream is blocked
	BlockStream(p peer.ID, dir network.Direction)

	// AllowPeer is invoked when attaching ac onnection to a peer is allowed
	AllowPeer(p peer.ID)
	// BlockPeer is invoked when attaching ac onnection to a peer is blocked
	BlockPeer(p peer.ID)

	// AllowProtocol is invoked when setting the protocol for a stream is allowed
	AllowProtocol(proto protocol.ID)
	// BlockProtocol is invoked when setting the protocol for a stream is blocked
	BlockProtocol(proto protocol.ID)
	// BlockProtocolPeer is invoked when setting the protocol for a stream is blocked at the per protocol peer scope
	BlockProtocolPeer(proto protocol.ID, p peer.ID)

	// AllowService is invoked when setting the protocol for a stream is allowed
	AllowService(svc string)
	// BlockService is invoked when setting the protocol for a stream is blocked
	BlockService(svc string)
	// BlockServicePeer is invoked when setting the service for a stream is blocked at the per service peer scope
	BlockServicePeer(svc string, p peer.ID)

	// AllowMemory is invoked when a memory reservation is allowed
	AllowMemory(size int)
	// BlockMemory is invoked when a memory reservation is blocked
	BlockMemory(size int)
}

type metrics struct {
	reporter MetricsReporter
}

// WithMetrics is a resource manager option to enable metrics collection
func ( MetricsReporter) Option {
	return func( *resourceManager) error {
		.metrics = &metrics{reporter: }
		return nil
	}
}

func ( *metrics) ( network.Direction,  bool) {
	if  == nil {
		return
	}

	.reporter.AllowConn(, )
}

func ( *metrics) ( network.Direction,  bool) {
	if  == nil {
		return
	}

	.reporter.BlockConn(, )
}

func ( *metrics) ( peer.ID,  network.Direction) {
	if  == nil {
		return
	}

	.reporter.AllowStream(, )
}

func ( *metrics) ( peer.ID,  network.Direction) {
	if  == nil {
		return
	}

	.reporter.BlockStream(, )
}

func ( *metrics) ( peer.ID) {
	if  == nil {
		return
	}

	.reporter.AllowPeer()
}

func ( *metrics) ( peer.ID) {
	if  == nil {
		return
	}

	.reporter.BlockPeer()
}

func ( *metrics) ( protocol.ID) {
	if  == nil {
		return
	}

	.reporter.AllowProtocol()
}

func ( *metrics) ( protocol.ID) {
	if  == nil {
		return
	}

	.reporter.BlockProtocol()
}

func ( *metrics) ( protocol.ID,  peer.ID) {
	if  == nil {
		return
	}

	.reporter.BlockProtocolPeer(, )
}

func ( *metrics) ( string) {
	if  == nil {
		return
	}

	.reporter.AllowService()
}

func ( *metrics) ( string) {
	if  == nil {
		return
	}

	.reporter.BlockService()
}

func ( *metrics) ( string,  peer.ID) {
	if  == nil {
		return
	}

	.reporter.BlockServicePeer(, )
}

func ( *metrics) ( int) {
	if  == nil {
		return
	}

	.reporter.AllowMemory()
}

func ( *metrics) ( int) {
	if  == nil {
		return
	}

	.reporter.BlockMemory()
}