package com.xinelu.web.controller.applet;

import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.R;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.exception.ServiceException;
import com.xinelu.familydoctor.applet.pojo.body.ResidentRescindApplyBody;
import com.xinelu.familydoctor.applet.pojo.query.ApplyQuery;
import com.xinelu.familydoctor.applet.pojo.vo.ResidentRescindApplyVo;
import com.xinelu.familydoctor.applet.service.IResidentRescindApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author mengkuiliang
 * @Description 解约申请控制器
 * @Date 2023-09-27 027 16:50
 * @Param
 * @return
 **/
@Api(tags = "解约申请控制器")
@RestController
@RequestMapping("/applet/rescind/apply")
public class ResidentRescindApplyController extends BaseController {

    @Resource
    private IResidentRescindApplyService rescindApplyService;

    @ApiOperation("提交解约申请")
    @PostMapping("save")
    public R<String> save(@Validated @RequestBody ResidentRescindApplyBody body) {
        rescindApplyService.insert(body);
        return R.ok();
    }

    @ApiOperation("取消解约申请")
    @GetMapping("cancel/{applyNo}")
    public R<String> cancel(@PathVariable String applyNo) {
        rescindApplyService.cancel(applyNo);
        return R.ok();
    }

    @ApiOperation(value = "获取解约请列表")
    @GetMapping("/getList")
    public TableDataInfo getList(ApplyQuery query) {
        try {
            startPage();
            List<ResidentRescindApplyVo> list = rescindApplyService.findList(query);
            return getDataTable(list);
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage());
        }
    }

    @ApiOperation(value = "获取解约申请详情")
    @GetMapping("/detail/{applyNo}")
    public R<ResidentRescindApplyVo> getRescindApply(@PathVariable String applyNo) {
        try {
            return R.ok(rescindApplyService.detail(applyNo));
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
    }

}
