package models

import (
	"fmt"
	"github.com/beego/beego/v2/adapter/orm"
	"github.com/beego/beego/v2/core/logs"
	"github.com/beego/beego/v2/server/web"
	"merchant/models/account"
	"merchant/models/agent"
	"merchant/models/menu"
	"merchant/models/merchant"
	"merchant/models/notify"
	"merchant/models/order"
	"merchant/models/payfor"
	"merchant/models/road"
	"merchant/models/user"
)

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")

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

	logs.Info("mysql init.....", link)

	_ = orm.RegisterDriver("mysql", orm.DRMySQL)
	_ = orm.RegisterDataBase("default", "mysql", link, 30, 30)
	orm.RegisterModel(
		new(user.UserInfo),
		new(menu.MenuInfo),
		new(menu.SecondMenuInfo),
		new(menu.PowerInfo),
		new(user.RoleInfo),
		new(account.BankCardInfo),
		new(road.RoadInfo),
		new(road.RoadPoolInfo),
		new(agent.AgentInfo),
		new(merchant.MerchantInfo),
		new(merchant.MerchantDeployInfo),
		new(account.AccountInfo),
		new(account.AccountHistoryInfo),
		new(order.OrderInfo),
		new(order.OrderProfitInfo),
		new(order.OrderSettleInfo),
		new(notify.NotifyInfo),
		new(merchant.MerchantLoadInfo),
		new(payfor.PayForInfo))
}
