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.SafetyCommitmentPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.extra.vo.SafetyCommitmentRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraSafetyCommitmentDO;
import cn.iocoder.yudao.module.system.service.extra.ElderlyExtraSafetyCommitmentService;
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/safetyCommitment")
@Validated
public class ElderlyExtraSafetyCommitmentController {

    @Resource
    private ElderlyExtraSafetyCommitmentService service;

    @PostMapping("/create")
    @Operation(summary = "创建长者安全承诺书")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyExtraSafetyCommitmentDO createReqVO) {
        return success(service.create(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "编辑长者安全承诺书")
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyExtraSafetyCommitmentDO 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<SafetyCommitmentRespVO>> findPage(@Valid SafetyCommitmentPageReqVO reqVO) {
        PageResult<ElderlyExtraSafetyCommitmentDO> pageResult = service.findPage(reqVO);
        return success(BeanUtils.toBean(pageResult, SafetyCommitmentRespVO.class));
    }

    @GetMapping("/getListByElderId")
    @Operation(summary = "根据长者ID获取长者安全承诺书列表")
    @Parameter(name = "elderId", description = "长者ID", required = true, example = "1024")
    public CommonResult<List<ElderlyExtraSafetyCommitmentDO>> 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<ElderlyExtraSafetyCommitmentDO> getDetail(@RequestParam("id") Long id) {
        return success(service.getDetail(id));
    }

}
