package com.sifang.modules.insurance.web;

import com.sifang.modules.insurance.request.InsuranceListEditReq;
import com.sifang.modules.insurance.service.InsuranceListService;
import com.sifang.modules.sunshine.SystemSetting.service.ProjectCompanyService;
import com.sifang.modules.sunshine.SystemSetting.utils.Result;
import com.sifang.modules.sunshine.partnerManagement.service.PartnerService;
import com.sifang.modules.sys.util.LayuiPage;
import com.sifang.modules.sys.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author DQChen
 * @date 2024-01-18 9:53
 */
@Controller
@RequestMapping("${adminPath}/insurance/")
public class InsuranceListController extends BaseController {

	@Autowired
	InsuranceListService insuranceListService;

	@Autowired
	ProjectCompanyService companyService;

	@Autowired
	PartnerService partnerService;

	/**
	 * 保险公司列表页面跳转接口
	 */
	@RequestMapping(value = "list")
	public String list(HttpServletRequest request, Model model){
		return "modules/insurance/setting/insuranceSet";
	}


	/**
	 * 保险公司信息列表数据
	 */
	@ResponseBody
	@RequestMapping(value = "insuranceListData")
	public Object insuranceListData(HttpServletRequest request){
		LayuiPage layuiPage = new LayuiPage(request);
		insuranceListService.list(getParams(request), layuiPage);
		return layuiPage.renderJson();
	}


	/**
	 * 跳转到添加页面
	 * @param model
	 * @return
	 */
	@RequestMapping("toAddPage")
	public Object toAddPage(Model model) {
		model.addAttribute("companys", companyService.getProjectCompany("1"));
		model.addAttribute("paterns", partnerService.partnerList());
		return "modules/insurance/setting/addInsurance";
	}

	/**
	 * 添加保险公司记录
	 * @param addReq
	 * @return
	 */
	@ResponseBody
	@RequestMapping("addInsurance")
	public Result addInsurance(@RequestBody InsuranceListEditReq addReq) {
		return insuranceListService.addInsurance(addReq);
	}

	@RequestMapping("toEditPage/{id}")
	public Object toEditPage(Model model,@PathVariable("id") String id) {
		model.addAttribute("companys", companyService.getProjectCompany("1"));
		model.addAttribute("paterns", partnerService.partnerList());
		model.addAttribute("insurance", insuranceListService.findById(id));
		return "modules/insurance/setting/editInsurance";
	}

	/**
	 * 修改保险公司记录
	 * @param editReq
	 * @return
	 */
	@ResponseBody
	@RequestMapping("editInsurance")
	public Result editInsurance(@RequestBody InsuranceListEditReq editReq) {
		return insuranceListService.editInsurance(editReq);
	}


	/**
	 * 跳转详情页面
	 * @param model
	 * @param id
	 * @return
	 */
	@RequestMapping("toDetail/{id}")
	public Object toDetail(Model model, @PathVariable("id") String id) {
		model.addAttribute("insurance", insuranceListService.findById(id));
		return "modules/insurance/";
	}

	/**
	 * 禁用
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("disable/{id}")
	public Result disable(@PathVariable("id") String id) {
		return insuranceListService.disable(id);
	}

	/**
	 * 启用
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("enable/{id}")
	public Result enable(@PathVariable("id") String id) {
		return insuranceListService.enable(id);
	}

	/**
	 * 启用
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("del/{id}")
	public Result del(@PathVariable("id") String id) {
		return insuranceListService.del(id);
	}


}
