package cygx

import (
	"github.com/beego/beego/v2/client/orm"
)

type CygxConfig struct {
	ConfigValue     string `description:"详情"`
	OperationButton bool   `description:"操作按钮1，true,允许，false 不予许"`
}

type NameAndUrl struct {
	Name string `description:"名称"`
	Url  string `description:"地址"`
}

type NameAndUrlList struct {
	List []*NameAndUrl
}

// 详情
func GetCygxConfigDetail() (item *CygxConfig, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_config  WHERE config_code= 'is_show_sustainable'`
	err = o.Raw(sql).QueryRow(&item)
	return
}

// 修改
func CygxConfigUpdate(newValue int) (err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `UPDATE cygx_config SET  config_value=?   WHERE config_code= 'is_show_sustainable'`
	_, err = o.Raw(sql, newValue).Exec()
	return
}

// 详情
func GetCygxConfigDetailByCode(code string) (item *CygxConfig, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_config  WHERE config_code= ?`
	err = o.Raw(sql, code).QueryRow(&item)
	return
}

// 修改
func CygxConfigUpdateByCode(configValue, newValue string) (err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `UPDATE cygx_config SET  config_value=?   WHERE config_code= ? `
	_, err = o.Raw(sql, configValue, newValue).Exec()
	return
}

func GetConfigByCode(configCode string) (item *CygxConfig, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_config WHERE config_code=? `
	err = o.Raw(sql, configCode).QueryRow(&item)
	return
}
