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.OutingConfirmationFormPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.extra.vo.OutingConfirmationFormRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraOutingConfirmationFormDO;
import cn.iocoder.yudao.module.system.service.extra.ElderlyExtraOutingConfirmationFormService;
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/outingConfirmationForm")
@Validated
public class ElderlyExtraOutingConfirmationFormController {

    @Resource
    private ElderlyExtraOutingConfirmationFormService service;

    @PostMapping("/create")
    @Operation(summary = "创建外出情况确认书")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyExtraOutingConfirmationFormDO createReqVO) {
        return success(service.create(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "编辑外出情况确认书")
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyExtraOutingConfirmationFormDO 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<OutingConfirmationFormRespVO>> findPage(@Valid OutingConfirmationFormPageReqVO reqVO) {
        PageResult<ElderlyExtraOutingConfirmationFormDO> pageResult = service.findPage(reqVO);
        return success(BeanUtils.toBean(pageResult, OutingConfirmationFormRespVO.class));
    }

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

}
