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.SignatureProxyApplicationPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.extra.vo.SignatureProxyApplicationRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraSignatureProxyApplicationDO;
import cn.iocoder.yudao.module.system.service.extra.ElderlyExtraSignatureProxyApplicationService;
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/signatureProxyApplication")
@Validated
public class ElderlyExtraSignatureProxyApplicationController {

    @Resource
    private ElderlyExtraSignatureProxyApplicationService service;

    @PostMapping("/create")
    @Operation(summary = "创建签名代理申请")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyExtraSignatureProxyApplicationDO createReqVO) {
        return success(service.create(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "编辑签名代理申请")
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyExtraSignatureProxyApplicationDO 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<SignatureProxyApplicationRespVO>> findPage(@Valid SignatureProxyApplicationPageReqVO reqVO) {
        PageResult<ElderlyExtraSignatureProxyApplicationDO> pageResult = service.findPage(reqVO);
        return success(BeanUtils.toBean(pageResult, SignatureProxyApplicationRespVO.class));
    }

    @GetMapping("/getListByElderId")
    @Operation(summary = "根据长者ID获取签名代理申请列表")
    @Parameter(name = "elderId", description = "长者ID", required = true, example = "1024")
    public CommonResult<List<ElderlyExtraSignatureProxyApplicationDO>> 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<ElderlyExtraSignatureProxyApplicationDO> getDetail(@RequestParam("id") Long id) {
        return success(service.getDetail(id));
    }

}
