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

/*
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <rmr/rmr.h>
#include <rmr/RIC_message_types.h>

void write_bytes_array(unsigned char *dst, void *data, int len) {
    memcpy((void *)dst, (void *)data, len);
}

#cgo CFLAGS: -I../
#cgo LDFLAGS: -lrmr_nng -lnng
*/
import "C"

import (
	"fmt"
	"github.com/spf13/viper"
	"strconv"
	"strings"
	"time"
	"unsafe"
)

var RMRCounterOpts = []CounterOpts{
	{Name: "Transmitted", Help: "The total number of transmited RMR messages"},
	{Name: "Received", Help: "The total number of received RMR messages"},
	{Name: "TransmitError", Help: "The total number of RMR transmission errors"},
	{Name: "ReceiveError", Help: "The total number of RMR receive errors"},
}

var RMRErrors = map[int]string{
	C.RMR_OK:             "state is good",
	C.RMR_ERR_BADARG:     "argument passed to function was unusable",
	C.RMR_ERR_NOENDPT:    "send/call could not find an endpoint based on msg type",
	C.RMR_ERR_EMPTY:      "msg received had no payload; attempt to send an empty message",
	C.RMR_ERR_NOHDR:      "message didn't contain a valid header",
	C.RMR_ERR_SENDFAILED: "send failed; errno has nano reason",
	C.RMR_ERR_CALLFAILED: "unable to send call() message",
	C.RMR_ERR_NOWHOPEN:   "no wormholes are open",
	C.RMR_ERR_WHID:       "wormhole id was invalid",
	C.RMR_ERR_OVERFLOW:   "operation would have busted through a buffer/field size",
	C.RMR_ERR_RETRY:      "request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)",
	C.RMR_ERR_RCVFAILED:  "receive failed (hard error)",
	C.RMR_ERR_TIMEOUT:    "message processing call timed out",
	C.RMR_ERR_UNSET:      "the message hasn't been populated with a transport buffer",
	C.RMR_ERR_TRUNC:      "received message likely truncated",
	C.RMR_ERR_INITFAILED: "initialization of something (probably message) failed",
	C.RMR_ERR_NOTSUPP:    "the request is not supported, or RMr was not initialized for the request",
}

type RMRParams struct {
	Mtype      int
	Payload    []byte
	PayloadLen int
	Meid       *RMRMeid
	Xid        string
	SubId      int
	Src        string
	Mbuf       *C.rmr_mbuf_t
}

func NewRMRClient() *RMRClient {
	p := C.CString(viper.GetString("rmr.protPort"))
	m := C.int(viper.GetInt("rmr.maxSize"))
	defer C.free(unsafe.Pointer(p))

	ctx := C.rmr_init(p, m, C.int(0))
	if ctx == nil {
		Logger.Error("rmrClient: Initializing RMR context failed, bailing out!")
	}

	return &RMRClient{
		context:   ctx,
		consumers: make([]MessageConsumer, 0),
		stat:      Metric.RegisterCounterGroup(RMRCounterOpts, "RMR"),
	}
}

func (m *RMRClient) Start(c MessageConsumer) {
	if c != nil {
		m.consumers = append(m.consumers, c)
	}

	for {
		Logger.Info("rmrClient: Waiting for RMR to be ready ...")

		if m.ready = int(C.rmr_ready(m.context)); m.ready == 1 {
			break
		}
		time.Sleep(10 * time.Second)
	}
	m.wg.Add(viper.GetInt("rmr.numWorkers"))

	if m.readyCb != nil {
		go m.readyCb(m.readyCbParams)
	}

	for w := 0; w < viper.GetInt("rmr.numWorkers"); w++ {
		go m.Worker("worker-"+strconv.Itoa(w), 0)
	}
	m.Wait()
}

func (m *RMRClient) Worker(taskName string, msgSize int) {
	p := viper.GetString("rmr.protPort")
	Logger.Info("rmrClient: '%s': receiving messages on [%s]", taskName, p)

	defer m.wg.Done()
	for {
		rxBuffer := C.rmr_rcv_msg(m.context, nil)
		if rxBuffer == nil {
			m.LogMBufError("RecvMsg failed", rxBuffer)
			m.UpdateStatCounter("ReceiveError")
			continue
		}
		m.UpdateStatCounter("Received")

		go m.parseMessage(rxBuffer)
	}
}

func (m *RMRClient) parseMessage(rxBuffer *C.rmr_mbuf_t) {
	if len(m.consumers) == 0 {
		Logger.Info("rmrClient: No message handlers defined, message discarded!")
		return
	}

	params := &RMRParams{}
	params.Mbuf = rxBuffer
	params.Mtype = int(rxBuffer.mtype)
	params.SubId = int(rxBuffer.sub_id)
	params.Meid = &RMRMeid{}

	meidBuf := make([]byte, int(C.RMR_MAX_MEID))
	if meidCstr := C.rmr_get_meid(rxBuffer, (*C.uchar)(unsafe.Pointer(&meidBuf[0]))); meidCstr != nil {
		params.Meid.RanName = strings.TrimRight(string(meidBuf), "\000")
	}

	xidBuf := make([]byte, int(C.RMR_MAX_XID))
	if xidCstr := C.rmr_get_xact(rxBuffer, (*C.uchar)(unsafe.Pointer(&xidBuf[0]))); xidCstr != nil {
		params.Xid = strings.TrimRight(string(xidBuf[0:32]), "\000")
	}

	srcBuf := make([]byte, int(C.RMR_MAX_SRC))
	if srcStr := C.rmr_get_src(rxBuffer, (*C.uchar)(unsafe.Pointer(&srcBuf[0]))); srcStr != nil {
		params.Src = strings.TrimRight(string(srcBuf[0:64]), "\000")
	}

	for _, c := range m.consumers {
		cptr := unsafe.Pointer(rxBuffer.payload)
		params.Payload = C.GoBytes(cptr, C.int(rxBuffer.len))
		params.PayloadLen = int(rxBuffer.len)

		err := c.Consume(params)
		if err != nil {
			Logger.Warn("rmrClient: Consumer returned error: %v", err)
		}
	}
}

func (m *RMRClient) Allocate() *C.rmr_mbuf_t {
	buf := C.rmr_alloc_msg(m.context, 0)
	if buf == nil {
		Logger.Error("rmrClient: Allocating message buffer failed!")
	}
	return buf
}

func (m *RMRClient) Free(mbuf *C.rmr_mbuf_t) {
	if mbuf == nil {
		return
	}
	C.rmr_free_msg(mbuf)
}

func (m *RMRClient) SendMsg(params *RMRParams) bool {
	return m.Send(params, false)
}

func (m *RMRClient) SendRts(params *RMRParams) bool {
	return m.Send(params, true)
}

func (m *RMRClient) Send(params *RMRParams, isRts bool) bool {
	txBuffer := params.Mbuf
	if txBuffer == nil {
		txBuffer = m.Allocate()
	}

	txBuffer.mtype = C.int(params.Mtype)
	txBuffer.sub_id = C.int(params.SubId)
	txBuffer.len = C.int(len(params.Payload))
	if params.PayloadLen != 0 {
		txBuffer.len = C.int(params.PayloadLen)
	}
	datap := C.CBytes(params.Payload)
	defer C.free(datap)

	if params != nil {
		if params.Meid != nil {
			b := make([]byte, int(C.RMR_MAX_MEID))
			copy(b, []byte(params.Meid.RanName))
			C.rmr_bytes2meid(txBuffer, (*C.uchar)(unsafe.Pointer(&b[0])), C.int(len(b)))
		}
		xidLen := len(params.Xid)
		if xidLen > 0 && xidLen <= C.RMR_MAX_XID {
			b := make([]byte, int(C.RMR_MAX_XID))
			copy(b, []byte(params.Xid))
			C.rmr_bytes2xact(txBuffer, (*C.uchar)(unsafe.Pointer(&b[0])), C.int(len(b)))
		}
	}
	C.write_bytes_array(txBuffer.payload, datap, txBuffer.len)

	return m.SendBuf(txBuffer, isRts)
}

func (m *RMRClient) SendBuf(txBuffer *C.rmr_mbuf_t, isRts bool) bool {
	var (
		currBuffer  *C.rmr_mbuf_t
		state       bool   = true
		counterName string = "Transmitted"
	)

	txBuffer.state = 0
	if isRts {
		currBuffer = C.rmr_rts_msg(m.context, txBuffer)
	} else {
		currBuffer = C.rmr_send_msg(m.context, txBuffer)
	}

	if currBuffer == nil {
		m.UpdateStatCounter("TransmitError")
		return m.LogMBufError("SendBuf failed", txBuffer)
	}

	// Just quick retry seems to help for K8s issue
	for j := 0; j < 3 && currBuffer != nil && currBuffer.state == C.RMR_ERR_RETRY; j++ {
		if isRts {
			currBuffer = C.rmr_rts_msg(m.context, currBuffer)
		} else {
			currBuffer = C.rmr_send_msg(m.context, currBuffer)
		}
	}

	if currBuffer.state != C.RMR_OK {
		counterName = "TransmitError"
		state = m.LogMBufError("SendBuf failed", currBuffer)
	}

	m.UpdateStatCounter(counterName)
	m.Free(currBuffer)
	return state
}

func (m *RMRClient) UpdateStatCounter(name string) {
	m.mux.Lock()
	m.stat[name].Inc()
	m.mux.Unlock()
}

func (m *RMRClient) RegisterMetrics() {
	m.stat = Metric.RegisterCounterGroup(RMRCounterOpts, "RMR")
}

func (m *RMRClient) Wait() {
	m.wg.Wait()
}

func (m *RMRClient) IsReady() bool {
	return m.ready != 0
}

func (m *RMRClient) SetReadyCB(cb ReadyCB, params interface{}) {
	m.readyCb = cb
	m.readyCbParams = params
}

func (m *RMRClient) GetRicMessageId(name string) (int, bool) {
	id, ok := RICMessageTypes[name]
	return id, ok
}

func (m *RMRClient) GetRicMessageName(id int) (s string) {
	for k, v := range RICMessageTypes {
		if id == v {
			return k
		}
	}
	return
}

func (m *RMRClient) LogMBufError(text string, mbuf *C.rmr_mbuf_t) bool {
	Logger.Debug(fmt.Sprintf("rmrClient: %s -> [tp=%v] %v - %s", text, mbuf.tp_state, mbuf.state, RMRErrors[int(mbuf.state)]))
	return false
}

// To be removed ...
func (m *RMRClient) GetStat() (r RMRStatistics) {
	return
}
