package models

import (
	"fmt"

	"github.com/beego/beego/v2/client/orm"

	"merchant/internal/models/account"
	"merchant/internal/models/agent"
	menu2 "merchant/internal/models/menu"
	merchant2 "merchant/internal/models/merchant"
	"merchant/internal/models/notify"
	order2 "merchant/internal/models/order"
	"merchant/internal/models/payfor"
	road2 "merchant/internal/models/road"
	user2 "merchant/internal/models/user"

	"github.com/beego/beego/v2/core/logs"
	"github.com/beego/beego/v2/server/web"
)

func init() {
	dbHost, _ := web.AppConfig.String("mysql::dbhost")
	dbUser, _ := web.AppConfig.String("mysql::dbuser")
	dbPassword, _ := web.AppConfig.String("mysql::dbpasswd")
	dbBase, _ := web.AppConfig.String("mysql::dbbase")
	dbPort, _ := web.AppConfig.String("mysql::dbport")
	debug := web.AppConfig.DefaultBool("mysql::debug", false)

	link := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbUser, dbPassword, dbHost, dbPort, dbBase)

	logs.Info("mysql init.....", link)
	orm.Debug = debug

	_ = orm.RegisterDriver("mysql", orm.DRMySQL)
	_ = orm.RegisterDataBase("default", "mysql", link)
	orm.RegisterModel(
		new(user2.UserInfo),
		new(menu2.MenuInfo),
		new(menu2.SecondMenuInfo),
		new(menu2.PowerInfo),
		new(user2.RoleInfo),
		new(account.BankCardInfo),
		new(road2.RoadInfo),
		new(road2.RoadPoolInfo),
		new(agent.AgentInfo),
		new(merchant2.MerchantInfo),
		new(merchant2.MerchantDeployInfo),
		new(account.AccountInfo),
		new(account.AccountHistoryInfo),
		new(order2.OrderInfo),
		new(order2.OrderProfitInfo),
		new(order2.OrderSettleInfo),
		new(notify.NotifyInfo),
		new(merchant2.MerchantLoadInfo),
		new(payfor.PayForInfo))
}
