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

import java.util.List;
import java.util.Map;

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

import org.linlinjava.jz.db.domain.HmEmployClock;
import org.linlinjava.jz.db.dto.hm.HmEmployClockUpdateDto;
import org.linlinjava.jz.db.dto.hm.HmSetTaskItemDTO;
import org.linlinjava.jz.db.dto.hm.HmTaskListData;
import org.linlinjava.jz.db.service.CustomerOrderService;
import org.linlinjava.jz.db.service.hm.HmEmployRelationService;
import org.linlinjava.jz.db.service.hm.HmEmployTaskSetService;
import org.linlinjava.jz.hm.util.HmResponseUtil;
import org.linlinjava.jz.service.HmEmployClockService;
import org.linlinjava.jz.service.HmTaskCenterService;
import org.springframework.beans.factory.annotation.Autowired;
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("employInfo")
@Valid
public class HmEmployInfoController {

	@Autowired
	HmTaskCenterService hmTaskCenterService;

	@Autowired
	HmEmployClockService hmEmployClockService;

	@Autowired
	CustomerOrderService customerOrderService;

	@Autowired
	HmEmployRelationService employRelationService;

	@Autowired
	HmEmployTaskSetService hmEmployTaskSetService;

	@ApiOperation(value = "根据雇佣关系，查询三者关系信息", notes = "根据雇佣关系，查询三者关系信息")
	@GetMapping(value = "getEmpInfo")
	public Object getEmpInfo(Long employRelationId) {
		Map<String, Object> data = employRelationService.getEmployInfo(employRelationId);

		return HmResponseUtil.ok(data);
	}

	@ApiOperation(value = "管家-详细信息-任务列表", notes = "管家-详细信息-任务列表")
	@GetMapping(value = "getTaskList")
	public Object getTaskList(int page, int limit, Long employRelationId) {
		List<HmTaskListData> selectTaskList = hmTaskCenterService.selectUserTaskList(page, limit, employRelationId);
		return HmResponseUtil.ok(selectTaskList);
	}

	@ApiOperation(value = "管家-详细信息-保姆服务记录", notes = "管家-详细信息-保姆服务记录")
	@GetMapping(value = "getServiceHistory")
	public Object getServiceHistory(int page, int limit, Long employRelationId) {
		List<HmEmployClock> sereviceHistory = hmEmployClockService.sereviceHistory(page, limit, employRelationId);
		return HmResponseUtil.ok(sereviceHistory);
	}

	@ApiOperation(value = "管家-详细信息-订单信息服务信息", notes = "管家-详细信息-订单信息服务信息")
	@GetMapping(value = "getOrderServiceInfo")
	public Object getOrderServiceInfo(Long employRelationId) {

		return customerOrderService.getOrderInfo(employRelationId);
	}

	@ApiOperation(value = "管家-详细信息-客户登录手机号修改", notes = "管家-详细信息-客户登录手机号修改")
	@GetMapping(value = "updateCustomerPhone")
	public Object updateCustomerPhone(@NotBlank @RequestParam String orderNo, @NotBlank @RequestParam String mobile,
			Long taskChildId) {
		employRelationService.updateCustomerTel(orderNo, mobile, taskChildId);
		return HmResponseUtil.ok();
	}

	@ApiOperation(value = "管家-详细信息-修改任务信息查询", notes = "管家-详细信息-修改任务信息查询")
	@GetMapping(value = "getServantTaskInfo")
	public Object getServantTaskInfo(Long employRelationId) {
		return hmEmployTaskSetService.getServantTaskInfo(employRelationId);
	}

	@ApiOperation(value = "管家-详细信息-修改任务信息-休息日，是否需要任务打卡", notes = "管家-详细信息-修改任务信息-休息日，是否需要任务打卡")
	@GetMapping(value = "updateRestDayIsClock")
	public Object updateRestDayIsClock(@NotBlank Integer isNeedClock, @NotBlank String restDay, Long taskChildId,
			@NotBlank String orderNo) {
		return employRelationService.updateRestDayIsClock(isNeedClock, restDay, taskChildId, orderNo);
	}

	@ApiOperation(value = "管家-每日任务编辑查询", notes = "管家-每日任务编辑查询")
	@GetMapping("/taskItemList")
	public Object taskItemList(@RequestParam @NotBlank String orderNo, @NotNull @RequestParam int taskType) {
		List<Map<String, Object>> mapList = hmEmployTaskSetService.selectChooseTaskItem(orderNo, taskType);
		return HmResponseUtil.ok(mapList);
	}

	@ApiOperation(value = "管家-每日任务编辑", notes = "管家-每日任务编辑 taskType 1日，2周，3月 ")
	@PostMapping("/setTask")
	public Object setTask(@Valid @RequestBody HmSetTaskItemDTO hmSetTaskItemDTO) {
		if (null == hmSetTaskItemDTO.getOrderNo()) {
			return HmResponseUtil.fail_null();
		}
		hmEmployTaskSetService.setTask(hmSetTaskItemDTO.getOrderNo(), hmSetTaskItemDTO);
		return HmResponseUtil.ok();
	}

	@ApiOperation(value = "管家-保姆服务记录编辑-查看每日打卡任务详情", notes = "管家-保姆服务记录编辑-查看每日打卡任务详情")
	@GetMapping("/getServantClockInfo")
	public Object getServantClockInfo(Long employClockId) {
		HmEmployClock servantClockInfo = hmEmployClockService.getServantClockInfo(employClockId);
		return HmResponseUtil.ok(servantClockInfo);
	}

	@ApiOperation(value = "管家-保姆服务记录每日打卡编辑-保存", notes = "管家-保姆服务记录每日打卡编辑-保存")
	@PostMapping("/updateServantClockInfo")
	public Object updateServantClockInfo(@RequestBody HmEmployClockUpdateDto emClock) {
		hmEmployClockService.updateEmployClockInof(emClock);
		return HmResponseUtil.ok();
	}
}
