/*
==================================================================================
  Copyright (c) 2019 AT&T Intellectual Property.
  Copyright (c) 2019 Nokia

   Licensed 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.
==================================================================================
*/

package xapp

import (
	"fmt"
	"github.com/gorilla/mux"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promauto"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	"sync"
)

//-----------------------------------------------------------------------------
// Alias
//-----------------------------------------------------------------------------
type CounterOpts prometheus.Opts
type Counter prometheus.Counter
type Gauge prometheus.Gauge

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------

type MetricGroupsCache struct {
	sync.RWMutex //This is for map locking
	counters     map[string]Counter
	gauges       map[string]Gauge
}

func (met *MetricGroupsCache) CIs(metric string) bool {
	met.RLock()
	defer met.RUnlock()
	_, ok := met.counters[metric]
	return ok
}

func (met *MetricGroupsCache) CInc(metric string) {
	met.RLock()
	defer met.RUnlock()
	met.counters[metric].Inc()
}

func (met *MetricGroupsCache) CAdd(metric string, val float64) {
	met.RLock()
	defer met.RUnlock()
	met.counters[metric].Add(val)
}

func (met *MetricGroupsCache) GIs(metric string) bool {
	met.RLock()
	defer met.RUnlock()
	_, ok := met.gauges[metric]
	return ok
}

func (met *MetricGroupsCache) GSet(metric string, val float64) {
	met.RLock()
	defer met.RUnlock()
	met.gauges[metric].Set(val)
}

func (met *MetricGroupsCache) GInc(metric string) {
	met.RLock()
	defer met.RUnlock()
	met.gauges[metric].Inc()
}

func (met *MetricGroupsCache) GDec(metric string) {
	met.RLock()
	defer met.RUnlock()
	met.gauges[metric].Dec()
}

func (met *MetricGroupsCache) CombineCounterGroups(srcs ...map[string]Counter) {
	met.Lock()
	defer met.Unlock()
	for _, src := range srcs {
		for k, v := range src {
			met.counters[k] = v
		}
	}
}

func (met *MetricGroupsCache) CombineGaugeGroups(srcs ...map[string]Gauge) {
	met.Lock()
	defer met.Unlock()
	for _, src := range srcs {
		for k, v := range src {
			met.gauges[k] = v
		}
	}
}

func NewMetricGroupsCache() *MetricGroupsCache {
	entry := &MetricGroupsCache{}
	entry.counters = make(map[string]Counter)
	entry.gauges = make(map[string]Gauge)
	return entry
}

//-----------------------------------------------------------------------------
// All counters/gauges registered via Metrics instances:
// Counter names are build from: namespace, subsystem, metric and possible labels
//-----------------------------------------------------------------------------
var globalLock sync.Mutex
var cache_allcounters map[string]Counter
var cache_allgauges map[string]Gauge

func init() {
	cache_allcounters = make(map[string]Counter)
	cache_allgauges = make(map[string]Gauge)
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
type Metrics struct {
	Namespace string
}

func NewMetrics(url, namespace string, r *mux.Router) *Metrics {
	if url == "" {
		url = "/ric/v1/metrics"
	}
	if namespace == "" {
		namespace = "ricxapp"
	}

	Logger.Info("Serving metrics on: url=%s namespace=%s", url, namespace)

	// Expose 'metrics' endpoint with standard golang metrics used by prometheus
	r.Handle(url, promhttp.Handler())

	return &Metrics{Namespace: namespace}
}

/*
 * Helpers
 */
func (m *Metrics) getFullName(opts prometheus.Opts, labels []string) string {
	labelname := ""
	for _, lbl := range labels {
		if len(labelname) == 0 {
			labelname += lbl
		} else {
			labelname += "_" + lbl
		}
	}
	return fmt.Sprintf("%s_%s_%s_%s", opts.Namespace, opts.Subsystem, opts.Name, labelname)
}

/*
 * Handling counters
 */
func (m *Metrics) registerCounter(opts CounterOpts) Counter {
	Logger.Info("Register new counter with opts: %v", opts)
	return promauto.NewCounter(prometheus.CounterOpts(opts))
}

func (m *Metrics) RegisterCounterGroup(opts []CounterOpts, subsytem string) (c map[string]Counter) {
	globalLock.Lock()
	defer globalLock.Unlock()
	c = make(map[string]Counter)
	for _, opt := range opts {
		opt.Namespace = m.Namespace
		opt.Subsystem = subsytem

		id := m.getFullName(prometheus.Opts(opt), []string{})
		if _, ok := cache_allcounters[id]; !ok {
			cache_allcounters[id] = m.registerCounter(opt)
		}

		c[opt.Name] = cache_allcounters[id]
	}

	return
}

/*
 * Handling gauges
 */
func (m *Metrics) registerGauge(opts CounterOpts) Gauge {
	Logger.Info("Register new gauge with opts: %v", opts)
	return promauto.NewGauge(prometheus.GaugeOpts(opts))
}

func (m *Metrics) RegisterGaugeGroup(opts []CounterOpts, subsytem string) (c map[string]Gauge) {
	globalLock.Lock()
	defer globalLock.Unlock()
	c = make(map[string]Gauge)
	for _, opt := range opts {
		opt.Namespace = m.Namespace
		opt.Subsystem = subsytem

		id := m.getFullName(prometheus.Opts(opt), []string{})
		if _, ok := cache_allgauges[id]; !ok {
			cache_allgauges[id] = m.registerGauge(opt)
		}

		c[opt.Name] = cache_allgauges[id]
	}

	return
}

/*
 * Handling counter vectors
 *
 * Example:

	vec := Metric.RegisterCounterVecGroup(
		[]CounterOpts{
			{Name: "counter1", Help: "counter1"},
			{Name: "counter2", Help: "counter2"},
		},
		[]string{"host"},
		"SUBSYSTEM")

	stat:=Metric.GetCounterGroupFromVects([]string{"localhost:8888"}, vec)

*/
type CounterVec struct {
	Vec  *prometheus.CounterVec
	Opts CounterOpts
}

func (m *Metrics) registerCounterVec(opts CounterOpts, labelNames []string) *prometheus.CounterVec {
	Logger.Info("Register new counter vector with opts: %v labelNames: %v", opts, labelNames)
	return promauto.NewCounterVec(prometheus.CounterOpts(opts), labelNames)
}

func (m *Metrics) RegisterCounterVecGroup(opts []CounterOpts, labelNames []string, subsytem string) (c map[string]CounterVec) {
	c = make(map[string]CounterVec)
	for _, opt := range opts {
		entry := CounterVec{}
		entry.Opts = opt
		entry.Opts.Namespace = m.Namespace
		entry.Opts.Subsystem = subsytem
		entry.Vec = m.registerCounterVec(entry.Opts, labelNames)
		c[opt.Name] = entry
	}
	return
}

func (m *Metrics) GetCounterGroupFromVectsWithPrefix(prefix string, labels []string, vects ...map[string]CounterVec) (c map[string]Counter) {
	globalLock.Lock()
	defer globalLock.Unlock()
	c = make(map[string]Counter)
	for _, vec := range vects {
		for name, opt := range vec {

			id := m.getFullName(prometheus.Opts(opt.Opts), labels)
			if _, ok := cache_allcounters[id]; !ok {
				Logger.Info("Register new counter from vector with opts: %v labels: %v prefix: %s", opt.Opts, labels, prefix)
				cache_allcounters[id] = opt.Vec.WithLabelValues(labels...)
			}
			c[prefix+name] = cache_allcounters[id]
		}
	}
	return
}

func (m *Metrics) GetCounterGroupFromVects(labels []string, vects ...map[string]CounterVec) (c map[string]Counter) {
	return m.GetCounterGroupFromVectsWithPrefix("", labels, vects...)
}

/*
 * Handling gauge vectors
 *
 * Example:

	vec := Metric.RegisterGaugeVecGroup(
		[]CounterOpts{
			{Name: "gauge1", Help: "gauge1"},
			{Name: "gauge2", Help: "gauge2"},
		},
		[]string{"host"},
		"SUBSYSTEM")

	stat:=Metric.GetGaugeGroupFromVects([]string{"localhost:8888"},vec)

*/
type GaugeVec struct {
	Vec  *prometheus.GaugeVec
	Opts CounterOpts
}

func (m *Metrics) registerGaugeVec(opts CounterOpts, labelNames []string) *prometheus.GaugeVec {
	Logger.Info("Register new gauge vector with opts: %v labelNames: %v", opts, labelNames)
	return promauto.NewGaugeVec(prometheus.GaugeOpts(opts), labelNames)
}

func (m *Metrics) RegisterGaugeVecGroup(opts []CounterOpts, labelNames []string, subsytem string) (c map[string]GaugeVec) {
	c = make(map[string]GaugeVec)
	for _, opt := range opts {
		entry := GaugeVec{}
		entry.Opts = opt
		entry.Opts.Namespace = m.Namespace
		entry.Opts.Subsystem = subsytem
		entry.Vec = m.registerGaugeVec(entry.Opts, labelNames)
		c[opt.Name] = entry

	}
	return
}

func (m *Metrics) GetGaugeGroupFromVectsWithPrefix(prefix string, labels []string, vects ...map[string]GaugeVec) (c map[string]Gauge) {
	globalLock.Lock()
	defer globalLock.Unlock()
	c = make(map[string]Gauge)
	for _, vec := range vects {
		for name, opt := range vec {

			id := m.getFullName(prometheus.Opts(opt.Opts), labels)
			if _, ok := cache_allgauges[id]; !ok {
				Logger.Info("Register new gauge from vector with opts: %v labels: %v prefix: %s", opt.Opts, labels, prefix)
				cache_allgauges[id] = opt.Vec.WithLabelValues(labels...)
			}
			c[prefix+name] = cache_allgauges[id]
		}
	}
	return
}

func (m *Metrics) GetGaugeGroupFromVects(labels []string, vects ...map[string]GaugeVec) (c map[string]Gauge) {
	return m.GetGaugeGroupFromVectsWithPrefix("", labels, vects...)
}
