package typeManage

import (
	"errors"
	"log-server/global"
)

type GameChannel struct {
	Id              int64     `gorm:"column:id;type:bigint(20);primaryKey" json:"id"`
	ChannelName     string    `gorm:"column:channel_name;type:varchar(255);not null" json:"channelName" binding:"required"`
	ChannelDesc     string    `gorm:"column:channel_desc;type:varchar(255);not null" json:"channelDesc" binding:"required"`
	DisplaySequence int64     `gorm:"column:display_sequence;type:smallint" json:"displaySequence" binding:"required"`
	GameCounts      int64     `gorm:"column:game_counts;type:int" json:"gameCounts" binding:"required"`
	CreateTime      LocalTime `gorm:"column:create_time;type:TIMESTAMP;" json:"createTime"`
	UpdateTime      LocalTime `gorm:"column:update_time;type:TIMESTAMP;" json:"updateTime"`
}

func (m *GameChannel) GetGameChannelById(id int) (gameChannel GameChannel, err error) {
	err = global.GVA_DB.Table("game_channel").Where("id = ?", id).Find(&gameChannel).Error
	if err != nil {
		return
	}
	if gameChannel.Id == 0 {
		return gameChannel, errors.New("数据错误")
	}
	return
}

func (m *GameChannel) GetGameChannelData() (mps map[int64]GameChannel, err error) {
	var gameChannel []GameChannel
	err = global.GVA_DB.Table("game_channel").Find(&gameChannel).Error
	if err != nil {
		return
	}
	if len(gameChannel) == 0 {
		return
	}
	var mp = map[int64]GameChannel{}
	for _, pc := range gameChannel {
		mp[pc.Id] = pc
	}
	return mp, err
}
