package models

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

type FollowingType string

const (
	Following   FollowingType = "following"
	Unfollowed  FollowingType = "unfollowed"
	listColumns               = "user_id, financial_analyst_id,financial_analyst_name, followed,followed_time"

	FollowingStatusColumns = "financial_analyst_id,financial_analyst_name, followed"
)

// UserAnalystFollowList 代表用户关注的研究员列表
type UserAnalystFollowList struct {
	ID                   int           `gorm:"primary_key;auto_increment;column:id"`
	UserID               int           `gorm:"not null;index:user_id"`
	FinancialAnalystID   int           `gorm:"not null;index:financial_analyst_id"`
	FinancialAnalystName string        `gorm:"not null;size:100"`
	Followed             FollowingType `gorm:"type:enum('following', 'unfollowed');not null"`
	FollowedTime         time.Time     `gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP;onupdate:CURRENT_TIMESTAMP"`
	CreatedTime          time.Time     `gorm:"type:timestamp;not null;default:0000-00-00 00:00:00"`
	UpdatedTime          time.Time     `gorm:"type:timestamp;null;onupdate:CURRENT_TIMESTAMP"`
}

func GetPostUser(authorId int, PublishTime string) (ids []int, err error) {
	o := orm.NewOrm()
	sql := "select distinct user_id from user_analyst_follow_list where financial_analyst_id = ? and followed = ? and followed_time <=? order by id asc"
	_, err = o.Raw(sql, authorId, Following, PublishTime).QueryRows(&ids)
	return
}
