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

import (
	"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
	"sync"
)


type Registry struct {
	register map[uint16]bool
	counter  uint16
	mutex sync.Mutex
}

// This method should run as a constructor
func (r *Registry) Initialize(seedsn uint16) {
	r.register = make(map[uint16]bool)
	r.counter = seedsn
}

// Reserves and returns the next free sequence number
func (r *Registry) ReserveSequenceNumber() (uint16, bool) {
	// Check is current SequenceNumber valid
	r.mutex.Lock()
	defer r.mutex.Unlock()
	sequenceNumber := r.counter
	if _, ok := r.register[sequenceNumber]; ok {
		xapp.Logger.Error("Invalid SeqenceNumber sequenceNumber: %v",sequenceNumber)
		return sequenceNumber, false
	}
	r.register[sequenceNumber] = false

	// Allocate next SequenceNumber value
	if r.counter == 65535 {
		r.counter = 0
	} else {
		r.counter++
	}
	return sequenceNumber, true
}

// This function checks the validity of the given subscription id
func (r *Registry) IsValidSequenceNumber(sn uint16) bool {
	r.mutex.Lock()
	defer r.mutex.Unlock()
	xapp.Logger.Debug("Registry map: %v", r.register)
	if _, ok := r.register[sn]; ok {
		return true
	}
	return false
}

// This function sets the give id as confirmed in the register
func (r *Registry) setSubscriptionToConfirmed(sn uint16) {
	r.mutex.Lock()
	defer r.mutex.Unlock()
	r.register[sn] = true
}

//This function sets the given id as unused in the register
func (r *Registry) deleteSubscription(sn uint16) {
	r.mutex.Lock()
	defer r.mutex.Unlock()
	r.register[sn] = false
}

//This function releases the given id as unused in the register
func (r *Registry) releaseSequenceNumber(sn uint16) bool {
	r.mutex.Lock()
	defer r.mutex.Unlock()
	if _, ok := r.register[sn]; ok {
		delete(r.register, sn)
		return true
	} else {
		return false
	}
}
