package org.linlinjava.jz.hm.web.butler;

import java.util.Map;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.linlinjava.jz.db.dto.hm.ButlerTaskTeachAddDto;
import org.linlinjava.jz.db.dto.hm.HmbutlerTaskClockDto;
import org.linlinjava.jz.db.service.hm.HmButlerTaskChildService;
import org.linlinjava.jz.db.service.hm.HmButlerTaskTeachService;
import org.linlinjava.jz.hm.util.HmResponseUtil;
import org.linlinjava.jz.service.HmButlerTaskClockService;
import org.linlinjava.jz.service.HmButlerTaskParentService;
import org.linlinjava.jz.service.HmSmsLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "管家拜访类任务", description = "管家拜访类任务")
@RestController
@RequestMapping("butlerVistTask")
public class ButlerVistTaskController {

	@Autowired
	HmButlerTaskChildService hmButlerTaskChildService;

	@Autowired
	HmButlerTaskParentService hmButlerTaskParentService;

	@Autowired
	HmButlerTaskClockService hmButlerTaskClockService;
	
	@Autowired
	HmButlerTaskTeachService hmButlerTaskTeachService;
	
	@Autowired
	HmSmsLogService hmSmsLogService;

	@ApiOperation(value = "管家拜访类-任务详情", notes = "管家拜访类-任务详情parentTaskId主任务id")
	@GetMapping(value = "info")
	public Object statistics(Long parentTaskId) {
		Map<String, Object> data = hmButlerTaskChildService.selectByTaskParentId(parentTaskId);
		return HmResponseUtil.ok(data);
	}

	@ApiOperation(value = "管家拜访类-主任务完成", notes = "管家拜访类-主任务完成,taskParentId主任务id")
	@GetMapping(value = "completeParentTask")
	public Object completeParentTask(Long parentTaskId) {
		hmButlerTaskParentService.completeParentTask(parentTaskId);
		return  HmResponseUtil.ok();
	}

	@ApiOperation(value = "管家拜访类-修改拜访时间", notes = "管家拜访类-修改拜访时间taskChildId 子任务id，date年月日")
	@GetMapping(value = "updateVisitTime")
	public Object updateVisitTime(@NotNull @RequestParam Long taskChildId, @NotNull @RequestParam String date) {
		hmButlerTaskChildService.updateVisitTime(taskChildId, date);
		return HmResponseUtil.ok();
	}

	@ApiOperation(value = "管家拜访类-上门拜访记录打卡", notes = "管家拜访类-上门拜访记录打卡")
	@PostMapping(value = "setVisitClock")
	public Object setVisitClock(@RequestBody @Valid HmbutlerTaskClockDto dto) {
		return hmButlerTaskClockService.visitClock(dto);
	}

	@ApiOperation(value = "管家拜访类-上门拜访记录打卡信息展示", notes = "管家拜访类-上门拜访记录打卡信息展示")
	@GetMapping(value = "getVisitClockInfo")
	public Object getVisitClockInfo(Long taskChildId) {
		return hmButlerTaskClockService.getVisitClockInfo(taskChildId);
	}
	
	@ApiOperation(value = "管家拜访类-跟教保姆记录查看", notes = "管家拜访类-跟教保姆记录查看")
	@GetMapping(value = "getServantTaskTeach")
	public Object getServantTaskTeach(Long taskChildId) {
//		return hmButlerTaskTeachService.getServantTaskTeach(taskChildId);
		Map<String, Object> data = hmButlerTaskTeachService.getServantTaskTeach(taskChildId);
		return HmResponseUtil.ok(data);
	}
	
	@ApiOperation(value = "管家拜访类-跟教保姆记录--录入", notes = "管家拜访类-跟教保姆记录--录入")
	@PostMapping(value = "addServantTaskTeach")
	public Object addServantTaskTeach(@RequestBody @Valid ButlerTaskTeachAddDto dto) {
		hmButlerTaskTeachService.addServantTaskTeach(dto);
		return HmResponseUtil.ok();
	}
	
	@ApiOperation(value = "管家邀请主顾双方使用小程序，发送短信", notes = "管家邀请主顾双方使用小程序，发送短信")
	@GetMapping(value = "invitationUseApp")
	public Object invitationUseApp(Long taskChildId) {
		String invitationUseApp = hmSmsLogService.invitationUseApp(taskChildId);
		if(null==invitationUseApp) {
			return HmResponseUtil.ok();
		}
		return HmResponseUtil.fail(invitationUseApp);
	}
	
	@ApiOperation(value = "管家邀请主顾双方使用小程序，从订单发起", notes = "管家邀请主顾双方使用小程序，从订单发起")
	@GetMapping(value = "invitationUseAppByOrder")
	public Object invitationUseAppByOrder(String orderNo) {
		String invitationUseApp = hmSmsLogService.invitationUseApps(orderNo);
		if(null==invitationUseApp) {
			return HmResponseUtil.ok();
		}
		return HmResponseUtil.fail(invitationUseApp);
	}

}
