package app_version

import (
	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/business/model"
	"git.rosy.net.cn/jx-callback/business/model/dao"
)

// AddApplicationVersion 添加app版本控制
func AddApplicationVersion(userName, appId, version string) error {
	config := &model.NewConfig{
		Type:  model.ConfigTypeApplication,
		Key:   appId,
		Value: version,
	}
	dao.WrapAddIDCULDEntity(config, userName)
	return dao.CreateEntity(dao.GetDB(), config)
}

// UpdateApplicationVersion 修改app版本
func UpdateApplicationVersion(appId, version string) error {
	sql := ` UPDATE new_config c SET c.value = ? WHERE c.key = ? AND c.deleted_at = ? `
	param := []interface{}{version, appId, utils.DefaultTimeValue}

	_, err := dao.ExecuteSQL(dao.GetDB(), sql, param...)
	return err
}

// GetApplicationVersion 查询小程序版本控制
func GetApplicationVersion(appId string) ([]*model.NewConfig, error) {
	return dao.QueryConfigs(dao.GetDB(), appId, model.ConfigTypeApplication, "")
}
