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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.riskdisclosurestatement.ElderlyRiskDisclosureStatementPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.riskdisclosurestatement.ElderlyRiskDisclosureStatementRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.riskdisclosurestatement.ElderlyRiskDisclosureStatementSaveReqVO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyRiskDisclosureStatementService;
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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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 javax.annotation.Resource;
import javax.validation.Valid;

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

@Tag(name = "管理后台 - 风险知情书")
@RestController
@RequestMapping("/elderly-risk-disclosure-statement")
@Validated
public class ElderlyRiskDisclosureStatementController {

    @Resource
    private ElderlyRiskDisclosureStatementService elderlyRiskDisclosureStatementService;

    @PostMapping("/create")
    @Operation(summary = "创建风险知情书")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyRiskDisclosureStatementSaveReqVO createReqVO) {
        if (createReqVO.getTenantId() == null) {
            createReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyRiskDisclosureStatementService.create(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新风险知情书")
    @TenantIgnore
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyRiskDisclosureStatementSaveReqVO updateReqVO) {
        if (updateReqVO.getTenantId() == null) {
            updateReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        elderlyRiskDisclosureStatementService.update(updateReqVO);
        return success(true);
    }

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

    @GetMapping("/get")
    @Operation(summary = "获得风险知情书详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @TenantIgnore
    public CommonResult<ElderlyRiskDisclosureStatementRespVO> get(@RequestParam("id") Long id) {
        return success(elderlyRiskDisclosureStatementService.get(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得风险知情书分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyRiskDisclosureStatementRespVO>> page(@Valid ElderlyRiskDisclosureStatementPageReqVO pageReqVO) {
        if (pageReqVO.getTenantIds() == null) {
            pageReqVO.setTenantIds(new Long[]{TenantContextHolder.getTenantId()});
        }
        return success(elderlyRiskDisclosureStatementService.getPage(pageReqVO));
    }
}

