package com.YuyeTech.HeartRate.game.gameInfo.controller;

import com.YuyeTech.HeartRate.VO.AiInfoVO;
import com.YuyeTech.HeartRate.VO.ResultVO;
import com.YuyeTech.HeartRate.dataobject.AiInfo;
import com.YuyeTech.HeartRate.service.AiInfoService;
import com.YuyeTech.HeartRate.utils.AliyunOSSUtil;
import com.YuyeTech.HeartRate.utils.ResultVOUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * 游戏端的信息处理
 * 比如给ai 获取头像，性别，姓名等
 * @author:slambb
 * @date:2020/3/25
 */
@RestController
@RequestMapping("/client_game")
public class ClientGameInfoController {
    @Autowired
    private AiInfoService aiInfoService;
    @Autowired
    private AliyunOSSUtil aliyunOSSUtil;

    /**
     * 随机获取AI信息
     * @return
     */
    @GetMapping("/ai_random_info")
    public ResultVO getRandomAIInfo(){

        List<AiInfo> aiInfoList = aiInfoService.getAllAiInfo();
        Random random = new Random();
        int n = random.nextInt(aiInfoList.size());
        AiInfo aiInfo= aiInfoList.get(n);
        //输出一个前端用的vo
        AiInfoVO aiInfoVO = new AiInfoVO();
        BeanUtils.copyProperties(aiInfo, aiInfoVO);
        //修改url，添加访问域名
        String url = aliyunOSSUtil.addDomainName(aiInfoVO.getAiAvatar());
        aiInfoVO.setAiAvatar(url);

        return ResultVOUtil.success(aiInfoVO);
    }


    @GetMapping("/transfer_picture")
    public ResultVO transferPicture(String url){

        Map map  = new HashMap();
        map.put("url",url);

        return ResultVOUtil.success(url);
    }



}

