package appmodel

import (
	"github.com/qit-team/snow-core/db"
	"sync"
	"time"
)

var (
	once sync.Once
	m    *AppModel
)

// 实体
type App struct {
	Id                int64
	MerchantId        int64     `xorm:"'merchant_id' bigint(20)"`
	AppName           string    `xorm:"'app_name' varchar(128)"`
	AppRemark         string    `xorm:"'app_remark' varchar(255)"`
	Status            int       `xorm:"'status' int(11)"`
	KeyType           int       `xorm:"'key_type' int(11)"`
	PublicKey         string    `xorm:"'public_key' varchar(1024)"`
	PrivateKey        string    `xorm:"'private_key' varchar(1024)"`
	MerchantPublicKey string    `xorm:"'merchant_public_key' varchar(1024)"`
	NotifyUrl         string    `xorm:"'notify_url' varchar(128)"`
	WhiteIp           string    `xorm:"'white_ip' varchar(128)"`
	CreateTime        time.Time `xorm:"'create_time' datetime created"`
	UpdateTime        time.Time `xorm:"'update_time' timestamp updated"`
	DeleteTime        time.Time `xorm:"'delete_time' timestamp deleted"`
}

// 表名
func (m *App) TableName() string {
	return "app"
}

// 私有化,防止被外部new
type AppModel struct {
	db.Model //组合基础Model,集成基础Model的属性和方法
}

// 单例模式
func GetInstance() *AppModel {
	once.Do(func() {
		m = new(AppModel)
		//m.DiName = "" //设置数据库实例连接,默认db.SingletonMain
	})
	return m
}