package models

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// GroupSendMsgAddReq 群发消息请求
type GroupSendMsgAddReq struct {
	JumpType    int8   `description:"跳转类型，1：h5；2：小程序；3：文字；4-图片"`
	LinkUrl     string `description:"跳转地址，长度255"`
	ImgUrl      string `description:"图片地址，长度255"`
	Title       string `description:"标题，长度64"`
	Description string `description:"摘要"`
	Label       string `description:"标签，多个标签用、隔开；长度255"`
}

// 群发消息
type GroupSendMsg struct {
	MsgId       int       `orm:"column(msg_id);pk" description:"消息Id"`
	JumpType    int8      `description:"跳转类型，1：h5；2：小程序；3：文字；4-图片"`
	LinkUrl     string    `description:"跳转地址"`
	ImgUrl      string    `description:"图片地址"`
	Title       string    `description:"标题"`
	Description string    `description:"摘要"`
	Label       string    `description:"标签"`
	Status      int8      `description:"发送结果，0：待发送，-1发送失败，1发送成功"`
	Remark      string    `description:"发送失败原因"`
	CreateTime  time.Time `description:"发送时间"`
}

// 新增群发消息
func (groupSendMsg *GroupSendMsg) Add() (err error) {
	o := orm.NewOrm()
	id, err := o.Insert(groupSendMsg)
	if err != nil {
		return
	}
	groupSendMsg.MsgId = int(id)
	return
}

// 修改群发消息
func (groupSendMsg *GroupSendMsg) Update(cols []string) (err error) {
	o := orm.NewOrm()
	_, err = o.Update(groupSendMsg, cols...)
	return
}
