package service

import (
	"encoding/json"
	"merchant/models/merchant"
	"merchant/models/road"
)

// QueryAllowedDeployInfoMM 获取指定商户的允许面额信息
func QueryAllowedDeployInfoMM(merchantUid, roadUid string) []merchant.ProfitMargin {
	resInfo := make([]merchant.ProfitMargin, 0)
	merchantInfoList := merchant.GetMerchantDeployByUid(merchantUid)
	if len(merchantInfoList) == 0 {
		return resInfo
	}

	for _, info := range merchantInfoList {
		if info.SingleRoadUid == roadUid {
			err := json.Unmarshal([]byte(info.SingleRoadPlatformRate), &resInfo)
			if err != nil {
				break
			}
		}
	}
	return resInfo
}

// QueryAllowedRoad 获取商户允许通道信息
func QueryAllowedRoad(merchantUid string) []road.SimpleRoadInfo {
	var resInfo []road.SimpleRoadInfo
	merchantInfoList := merchant.GetMerchantDeployByUid(merchantUid)
	if len(merchantInfoList) == 0 {
		return resInfo
	}

	//创建列表
	var roadIdList []string
	for _, info := range merchantInfoList {
		roadIdList = append(roadIdList, info.SingleRoadUid)
	}

	roadInfoList := road.GetRoadInfosByRoadUids(roadIdList)

	for _, info := range roadInfoList {
		resInfo = append(resInfo, road.SimpleRoadInfo{
			ProductCode: info.ProductCode,
			RoadName:    info.RoadName,
		})
	}
	return resInfo
}
