package com.yihu.wlyy.web.patient.consult;

import io.swagger.annotations.Api;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yihu.wlyy.entity.consult.ConsultMoVi;
import com.yihu.wlyy.entity.doctor.profile.DoctorComment;
import com.yihu.wlyy.service.app.consult.ConsultMoviService;
import com.yihu.wlyy.service.app.consult.DoctorCommentService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.WeixinBaseController;

/**
 * 患者端：视频咨询控制类
 * 
 * @author George
 */
@Controller
@RequestMapping(value = "/patient/consult_movi")
@Api(description = "视频咨询")
public class ConsultMoviController extends WeixinBaseController {

	@Autowired
	private ConsultMoviService consultMoviService;
	@Autowired
	private DoctorCommentService doctorCommentService;

	/**
	 * 视频咨询三师医生查询接口
	 * @return
	 */
	@RequestMapping(value = "doctors")
	@ResponseBody
	public String doctors() {
		try {
			JSONArray jsonArray = new JSONArray();
			return write(200, "查询成功！", "list", jsonArray);
		} catch (Exception e) {
			error(e);
			return invalidUserException(e, -1, "查询失败！");
		}
	}

	/**
	 * 添加电话视频咨询预约
	 * @param target 预约类型：1指定医生，2三师预约
	 * @param type 咨询类型，1电话咨询，2视频咨询
	 * @param family 家人标识
	 * @param doctor 指定医生标识
	 * @param scheduling 排班标识
	 * @param appo_date 预约日期
	 * @param appo_week 预约星期
	 * @param hour_begin 预约开始时间
	 * @param hour_end 预约结束时间
	 * @param content 咨询内容说明
	 * @param imageUrls 图片URL，多图逗号分隔
	 * @return
	 */
	@RequestMapping(value = "add")
	@ResponseBody
	public String add(@RequestParam(required = false) Integer target, @RequestParam(required = false) Integer type, @RequestParam(required = false) String family, @RequestParam(required = false) String doctor, String scheduling, String appo_date, int appo_week, String hour_begin, String hour_end, String content, @RequestParam(required = false) String images) {
		try {
			return success("预约成功！");
		} catch (Exception e) {
			error(e);
			return error(-1, "预约失败！");
		}
	}

	/**
	 * 视频咨询评论
	 * @param consult 视频咨询标识
	 * @param content 评价内容
	 * @param star 星级
	 * @return 操作结果
	 */
	@RequestMapping(value = "comment")
	@ResponseBody
	public String comment(String consult, String content, int star) {
		try {
			// 查询视频咨询信息
			ConsultMoVi cmv = consultMoviService.findByCode(consult);
			String doctor = null;
			if (cmv.getTarget() == 1) {
				// 指定医生
				doctor = cmv.getDoctor();
			} else {
				// 指定团队，查询最后处理人员
				doctor = consultMoviService.findToDoctor(consult);
			}
			// 保存评价
			DoctorComment comment = doctorCommentService.consultMoViComment(getUID(), consult, content, doctor, star, 1);
			if (comment == null) {
				return error(-1, "评价失败！");
			}
			return success("感谢您的评价！");
		} catch (Exception e) {
			error(e);
			return invalidUserException(e, -1, "评价失败！");
		}
	}
}
