package model

import (
	"database/sql/driver"
	"encoding/json"
)

type Config struct {
	/*
		配置文件表
	*/
	Id      int64  `gorm:"primary_key;column:id" json:"id"`
	Pid     int64  `gorm:"column:pid" json:"pid"`         // 父级ID
	Code    string `gorm:"column:code" json:"code"`       // 参数key
	Comment string `gorm:"column:comment" json:"comment"` // 参数值
	Status  int64  `gorm:"column:status" json:"status"`   // 参数状态
	Name    string `gorm:"column:name" json:"name"`       // 参数名称
	Type    string `gorm:"column:type" json:"type"`       // 类型 text file images
	Options string `gorm:"column:options" json:"options"` // 值范围
	Sort    int64  `gorm:"column:sort" json:"sort"`       // 排序
	FileUrl string `gorm:"-" json:"fileUrl"`              // 文件地址
}

func (Config) TableName() string {
	return "config"
}

type ConfigJson struct {
	Key   string `json:"key"`   // 内容
	Value string `json:"value"` // 值
	Type  string `json:"type"`  // 类型 text - image - file
	Memo  string `json:"memo"`  // 描述
}

type Log struct {
	/*
		操作日志表
	*/
	Id         int64  `gorm:"primary_key;column:id" json:"id"`
	Uid        int64  `gorm:"column:uid" json:"uid"`                //用户uid
	Name       string `gorm:"column:name" json:"name"`              //操作人
	Event      string `gorm:"column:event" json:"event"`            //操作事件
	Ip         string `gorm:"column:ip" json:"ip"`                  //操作IP
	A1         string `gorm:"column:a1" json:"a1"`                  //操作IP地址
	Data       string `gorm:"column:data" json:"data"`              //操作数据
	CreateTime int64  `gorm:"column:create_time" json:"createTime"` //操作时间
	UserType   string `gorm:"column:user_type" json:"userType"`     //用户类型 0-用户端 1-管理端
	IsSuper    string `gorm:"column:is_super" json:"isSuper"`       //是否超级权限操作 0-否 1-是
}

func (Log) TableName() string {
	return "log"
}

type Translate struct {
	/*
		翻译
	*/
	Id          int64        `gorm:"primary_key;column:id" json:"id"`        // 翻译标识
	Type        string       `gorm:"column:type" json:"type"`                // 类型 0-admin 1-App 2-官网
	LanguageKey string       `gorm:"column:language_key" json:"languageKey"` // 翻译Key
	Src         string       `gorm:"column:src" json:"src"`                  // 翻译值
	To          TranslateTos `gorm:"column:to" json:"to"`                    // 翻译数据
	CreateTime  int64        `gorm:"column:create_time" json:"createTime"`   // 创建时间
}

func (Translate) TableName() string {
	return "translate"
}

type TranslateTos []*TranslateTo

type TranslateTo struct {
	GoogleKey string `json:"googleKey"` //语言标识
	To        string `json:"to"`
}

func (j *TranslateTos) Scan(value interface{}) error {
	return json.Unmarshal(value.([]byte), &j)
}

func (j TranslateTos) Value() (driver.Value, error) {
	return json.Marshal(j)
}

type Resource struct {
	/*
		资源
		Type :
			Image
			Voice
			Video
			Pdf
			File
	*/

	Id         int64  `gorm:"primary_key;column:id" json:"id"`
	Type       string `gorm:"column:type" json:"type"`              // 类型
	CreateTime int64  `gorm:"column:create_time" json:"createTime"` // 创建时间
	To         string `gorm:"column:to" json:"to"`                  // 资源数据
}

func (Resource) TableName() string {
	return "resource"
}

type Version struct {
	/*
		版本表
	*/
	Id         int64  `gorm:"primary_key;column:id" json:"id"`      // id
	Version    string `gorm:"column:version" json:"version"`        // 版本号
	Type       string `gorm:"column:type" json:"type"`              // 类型 0-管理端 1-H5APP 2-H5PC 3-AppDownPage 4-苹果MobileConfig 5-server
	PublicPath string `gorm:"column:public_path" json:"publicPath"` // 静态资源路径
	CreateTime int64  `gorm:"column:create_time" json:"createTime"` // 时间
	Process    string `gorm:"column:process" json:"process"`        // 状态 0-上传成功 1-上传中,2-上传失败
	Status     string `gorm:"column:status" json:"status"`          // 0-开启,1-关闭,
	Data       JSON   `gorm:"column:data" json:"data"`              // 数据
	Memo       string `gorm:"column:memo" json:"memo"`              // 说明
	Operator   string `gorm:"column:operator" json:"operator"`      // 操作人
	Force      string `gorm:"column:force" json:"force"`            // 是否强制更新 0-是 1-否
}

func (Version) TableName() string {
	return "version"
}

type SysLanguage struct {
	/*
		语言表
	*/
	Id           int64  `gorm:"primary_key;column:id" json:"id"`
	ResourceId   int64  `gorm:"column:resource_id" json:"resourceId"`     //图标地址
	Key          string `gorm:"column:key" json:"key"`                    //en - zh
	GoogleKey    string `gorm:"column:google_key" json:"googleKey"`       //谷歌翻译key
	Name         string `gorm:"column:name" json:"name"`                  //语言名称
	ChineseName  string `gorm:"column:chinese_name" json:"chineseName"`   //中文名称
	Sort         int64  `gorm:"column:sort" json:"sort"`                  //排序
	Akey         string `gorm:"column:akey" json:"akey"`                  //语言包切换标识
	LanguageCode string `gorm:"column:language_code" json:"languageCode"` //语言代码
	CountryCode  string `gorm:"column:country_code" json:"countryCode"`   //城市代码
	IsDefault    string `gorm:"column:is_default" json:"isDefault"`       //是否默认 0-是 1-否
	IsShow       string `gorm:"column:is_show" json:"isShow"`             //前端是否显示
}

func (SysLanguage) TableName() string {
	return "sys_language"
}

type SysLanguageShow struct {
	Code string `json:"code"` // 语言包切换标识
	Name string `json:"name"` // 语言名称
	Icon string `json:"icon"` // 图标
}

type Timezone struct {
	/*
		时区表
	*/
	Id        int64  `gorm:"primary_key;column:id" json:"id"`
	Title     string `gorm:"column:title" json:"title"`          // 时区名称
	Value     string `gorm:"column:value" json:"value"`          // 时区代码
	IsDefault string `gorm:"column:is_default" json:"isDefault"` // 默认时区 0-默认
	Sort      int64  `gorm:"column:sort" json:"sort"`            // 排序
}

func (Timezone) TableName() string {
	return "timezone"
}

type BlackList struct {
	Id int64      `gorm:"primary_key;column:id" json:"id"`
	Ip ArryString `gorm:"column:ip" json:"ip"` // 黑名单ip
}

func (BlackList) TableName() string {
	return "black_list"
}

type Code struct {
	/*
		验证码
	*/
	Id         int64  `gorm:"primary_key;column:id" json:"id"`      // 用户ID
	Account    string `gorm:"column:account" json:"account"`        // 邮箱/手机号
	Code       string `gorm:"column:code" json:"code"`              // 验证码
	Type       string `gorm:"column:type" json:"type"`              // 类型 0-注册 1-登陆 2-找回密码 3-绑定 4-修改密码 5-修改支付密码
	Status     string `gorm:"column:status" json:"status"`          // 状态 0-发送成功 1-发送失败
	Memo       string `gorm:"column:memo" json:"memo"`              // 发送失败原因
	CreateTime int64  `gorm:"column:create_time" json:"createTime"` // 发送时间
}

func (Code) TableName() string {
	return "code"
}