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.PowerOfAttorneyPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.extra.vo.PowerOfAttorneyRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraPowerOfAttorneyDO;
import cn.iocoder.yudao.module.system.service.extra.ElderlyExtraPowerOfAttorneyService;
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/powerOfAttorney")
@Validated
public class ElderlyExtraPowerOfAttorneyController {

    @Resource
    private ElderlyExtraPowerOfAttorneyService service;

    @PostMapping("/create")
    @Operation(summary = "创建授权委托书")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyExtraPowerOfAttorneyDO createReqVO) {
        return success(service.create(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "编辑授权委托书")
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyExtraPowerOfAttorneyDO 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<PowerOfAttorneyRespVO>> findPage(@Valid PowerOfAttorneyPageReqVO reqVO) {
        PageResult<ElderlyExtraPowerOfAttorneyDO> pageResult = service.findPage(reqVO);
        return success(BeanUtils.toBean(pageResult, PowerOfAttorneyRespVO.class));
    }

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

}
