package model

import (
	"gorm.io/gorm/clause"

	"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
	"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
	"chaitin.cn/patronus/safeline-2/management/webserver/utils"
)

type Options struct {
	Base
	Key   string `gorm:"column:key;uniqueIndex"`
	Value string `gorm:"column:value;"`
}

func initOptions() error {
	db := database.GetDB()

	secretKey := Options{Key: constants.SecretKey, Value: utils.RandStr(32)}
	db.Clauses(clause.OnConflict{DoNothing: true}).Create(&secretKey)

	machineId := Options{Key: constants.MachineID, Value: utils.RandStr(32)}
	_ = db.Clauses(clause.OnConflict{DoNothing: true}).Create(&machineId)

	return nil
}
