package versionapi

import (
	"log/slog"

	"easyaudioencode/domain/version"
	"easyaudioencode/domain/version/store/versiondb"

	"git.lnton.com/lnton/pkg/orm"
	"gorm.io/gorm"
)

// 通过修改版本号，来控制是否执行表迁移
var (
	DBVersion = "0.0.20"
	DBRemark  = "增加同步记录表"
)

// NewVersionCore ...
func NewVersionCore(db *gorm.DB) version.Core {
	vdb := versiondb.NewDB(db)
	core := version.NewCore(vdb)
	isOK := core.IsAutoMigrate(DBVersion)
	vdb.AutoMigrate(isOK)
	if isOK {
		slog.Info("更新数据库表结构")
	}
	orm.SetEnabledAutoMigrate(isOK)
	return core
}
