package company

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

const (
	ConfAreaCodeListKey = "area_code_list" // 手机号区号列表
	ConfEnAuthRoleKey   = "en_auth_role"   // 英文权限角色配置Key
)

type CrmConfig struct {
	ConfigValue string `description:"详情"`
}

func GetConfigValueByCode(configCode string) (total int, err error) {
	o := orm.NewOrm()
	sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
	err = o.Raw(sql, configCode).QueryRow(&total)
	return
}

// 修改
func CrmConfigUpdate(newValue, configCode string) (err error) {
	o := orm.NewOrm()
	sql := `UPDATE crm_config SET  config_value=?   WHERE config_code=  ?`
	_, err = o.Raw(sql, newValue, configCode).Exec()
	return
}

func GetConfigDetailByCode(configCode string) (item CrmConfig, err error) {
	o := orm.NewOrm()
	sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
	err = o.Raw(sql, configCode).QueryRow(&item)
	return
}

// ConfEnAuthRole 配置-英文权限角色
type ConfEnAuthRole struct {
	RoleCode string `description:"角色编码"`
	RoleName string `description:"角色名称"`
	SyncCrm  bool   `description:"是否同步CRM"`
}
