package entity

import (
	"context"
	"strings"

	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck"
)

var (
	PowerCheck powercheck.PowerCheck
)

type UserInfoRpc struct {
	AppId        string //appId 剑鱼 10000
	UserId       string //用户id
	BaseUserId   int64  //用户基本id
	EntId        int64  //企业id
	EntUserId    int64  //企业用户id
	AccountId    int64  //账户id
	PositionType int64  //职位类型 @个人 1企业
	PositionId   int64  //职位id
	MgoUserId    string //原userId
}

// GetUserPowers  获取用户权益信息
func (ui *UserInfoRpc) GetUserPowers() *powercheck.CheckResp {
	req := &powercheck.CheckReq{
		Appid:        ui.AppId,
		Userid:       ui.MgoUserId,
		BaseUserId:   ui.BaseUserId,
		AccountId:    ui.AccountId,
		EntId:        ui.EntId,
		PositionType: ui.PositionType,
		PositionId:   ui.PositionId,
	}
	checkResp, err := PowerCheck.Check(context.Background(), req)
	if err == nil {
		return checkResp
	}
	return nil
}

// GetQueryItems 免费 标题(title)  正文(content) 老用户【中标企业(winner)】
// 付费用户 全部(all)、标题(title)  正文(content)  会员: 采购单位(buyer) 中标企业(winner) 招标代理机构(agency) 附件(file)
// 项目名称projectname和标的物purchasing(ppa)
func (ui *UserInfoRpc) GetQueryItems(selectType string, limitOldTime, registerData int64, isPay bool) (items []string) {
	if isPay {
		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 := registerData != 0 && 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
}
