package util

import (
	"strings"
)

// VipState 是否是付费用户
type VipState struct {
	VipState     int64 //超级订阅状态(1普通 2升级版)
	BigMember    int64 //大会员状态
	EntMember    int64 //商机管理用户状态
	RegisterData int64 //注册时间
	IsOldVip     bool  //老版超级订阅  超前项目
	IsNewEnt     bool  //新版商机管理
}

// IsPayedUser 是否是付费账户
func (vs *VipState) IsPayedUser() bool {
	return vs.VipState > 0 || vs.BigMember > 0 || vs.EntMember > 0
}

// GetQueryItems 免费 标题(title)  正文(content) 老用户【中标企业(winner)】
// 付费用户 全部(all)、标题(title)  正文(content)  会员: 采购单位(buyer) 中标企业(winner) 招标代理机构(agency) 附件(file)
// 项目名称projectname和标的物purchasing(ppa)
func (vs *VipState) GetQueryItems(selectType string, limitOldTime int64) (items []string) {
	if vs.IsPayedUser() {
		for _, t := range strings.Split(selectType, ",") {
			if t == "content" {
				items = append(items, "detail")
			} else if t == "buyer" {
				items = append(items, "buyer.mbuyer")
			} else if t == "winner" {
				items = append(items, "s_winner.mwinner")
			} else if t == "agency" {
				items = append(items, "agency.magency")
			} else if t == "title" {
				items = append(items, "title")
			} else if t == "ppa" {
				items = append(items, []string{"purchasing", "projectname.pname"}...)
			} else if t == "file" { //dev4.7.8 标讯优化：搜索范围附件-》全部用户可用
				items = append(items, "filetext")
			}
		}
		return
	}
	//老用户 使用付费功能
	isOldUser := vs.RegisterData != 0 && vs.RegisterData < limitOldTime
	for _, t := range strings.Split(selectType, ",") {
		if t == "winner" && isOldUser {
			items = append(items, "s_winner.mwinner")
		} else if t == "title" {
			items = append(items, "title")
		} else if t == "content" {
			items = append(items, "detail")
		} else if t == "file" { //dev4.7.8 标讯优化：搜索范围附件-》全部用户可用
			items = append(items, "filetext")
		}
	}
	return
}
