package db

import (
	"github.com/sirupsen/logrus"
)

var c Config

type Config struct {
	Base
	RadarHeight      int  `form:"radar_height" json:"radar_height"`
	RadarAngle       int  `form:"radar_angle" json:"radar_angle"`
	RadarMinDistance int  `form:"radar_min_distance" json:"radar_min_distance"`
	RadarMaxDistance int  `form:"radar_max_distance" json:"radar_max_distance"`
	RadarMinSpeed    int  `form:"radar_min_speed" json:"radar_min_speed"`
	RadarMaxSpeed    int  `form:"radar_max_speed" json:"radar_max_speed"`
	RadarWaveform    bool `form:"radar_waveform" json:"radar_waveform"`
	TriggerDistance  int  `form:"trigger_distance" json:"trigger_distance"`
	TriggerSpeed     int  `form:"trigger_speed" json:"trigger_speed"`
}

func initConfig() {
	if err := DB.FirstOrCreate(&c).Error; err != nil {
		logrus.Fatal("could not init db config")
	}
}

func SetConfig(sc Config) error {
	c = sc
	if err := DB.Save(&c).Error; err != nil {
		return err
	}
	return nil
}
func GetConfig() *Config {
	return &c
}
