package cn.iocoder.yudao.module.system.controller.admin.extra;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.extra.vo.RiskDisclosurePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.extra.vo.RiskDisclosureRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraRiskDisclosureDO;
import cn.iocoder.yudao.module.system.service.extra.ElderlyExtraRiskDisclosureService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * （附件）风险知情书 Controller
 *
 * @author 管理员
 */
@Tag(name = "管理后台 - 风险知情书")
@RestController
@RequestMapping("/elderly/extra/riskDisclosure")
@Validated
public class ElderlyExtraRiskDisclosureController {

    @Resource
    private ElderlyExtraRiskDisclosureService service;

    @PostMapping("/create")
    @Operation(summary = "创建风险知情书")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyExtraRiskDisclosureDO createReqVO) {
        return success(service.create(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "编辑风险知情书")
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyExtraRiskDisclosureDO updateReqVO) {
        service.update(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除风险知情书")
    @Parameter(name = "id", description = "风险知情书ID", required = true, example = "1024")
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        service.delete(id);
        return success(true);
    }

    @GetMapping("/findPage")
    @Operation(summary = "风险知情书分页列表")
    public CommonResult<PageResult<RiskDisclosureRespVO>> findPage(@Valid RiskDisclosurePageReqVO reqVO) {
        PageResult<ElderlyExtraRiskDisclosureDO> pageResult = service.findPage(reqVO);
        return success(BeanUtils.toBean(pageResult, RiskDisclosureRespVO.class));
    }

    @GetMapping("/getListByElderId")
    @Operation(summary = "根据长者ID获取风险知情书列表")
    @Parameter(name = "elderId", description = "长者ID", required = true, example = "1024")
    public CommonResult<List<ElderlyExtraRiskDisclosureDO>> getListByElderId(@RequestParam("elderId") Long elderId) {
        return success(service.getListByElderId(elderId));
    }

    @GetMapping("/getDetail")
    @Operation(summary = "获取风险知情书详情")
    @Parameter(name = "id", description = "风险知情书ID", required = true, example = "1024")
    public CommonResult<ElderlyExtraRiskDisclosureDO> getDetail(@RequestParam("id") Long id) {
        return success(service.getDetail(id));
    }

}
