package main

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/AFASystems/presence/internal/pkg/model"
	"github.com/redis/go-redis/v9"
)

func main() {
	ctx := context.Background()
	client := redis.NewClient(&redis.Options{
		Addr:     "127.0.0.1:6379",
		Password: "",
	})
}

func getLikelyLocations(client *redis.Client, ctx context.Context) {
	beaconsList, err := client.Get(ctx, "beaconsList").Result()
	var beacons = make(map[string]model.Beacon)
	if err == redis.Nil {
		fmt.Println("no beacons list, starting empty")
	} else if err != nil {
		panic(err)
	} else {
		json.Unmarshal([]byte(beaconsList), &beacons)
	}

	for id, beacon := range beacons {
		if len(beacon.Beacon_metrics) == 0 {
			continue
		}

		if isExpired(&beacon, settings) {
			handleExpiredBeacon(&beacon, cl, ctx)
			continue
		}

		best := calculateBestLocation(&beacon)
		updateBeaconState(&beacon, best, settings, ctx, cl)

		appendHTTPResult(ctx, beacon, best)
		ctx.Beacons.Beacons[id] = beacon
	}
}

// get likely locations:
/*
1. Locks the http_results list
2. inits list to empty struct type -> TODO: what is this list used for
3. loops through beacons list -> should be locked?
4. check for beacon metrics -> how do you get beacon metrics, I guess it has an array of timestamps
5. check for threshold value in the settings
5.1. check for property expired location
5.2. if location is not expired -> mark it as expired, generate message and send to all clients,
	 if clients do not respond close the connection
6. Init best location with type Best_location{} -> what is this type
7. make locations list -> key: string, val: float64
7.1 set weight for seen and rssi
7.2 loop over metrics of the beacon -> some alogirthm based on location value

I think the algorithm is recording names of different gateways and their rssi's and then from
that it checks gateway name and makes decisions based on calculated values

7.3 writes result in best location and updates list location history with this name if the list
is longer than 10 elements it removes the first element


*/
