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.CheckInTabPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.extra.vo.CheckInTabRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraCheckInTabDO;
import cn.iocoder.yudao.module.system.service.extra.ElderlyExtraCheckInTabService;
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/checkInTab")
@Validated
public class ElderlyExtraCheckInTabController {

    @Resource
    private ElderlyExtraCheckInTabService service;

    @PostMapping("/create")
    @Operation(summary = "创建入住登记表")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyExtraCheckInTabDO createReqVO) {
        return success(service.create(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "编辑入住登记表")
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyExtraCheckInTabDO 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<CheckInTabRespVO>> findPage(@Valid CheckInTabPageReqVO reqVO) {
        PageResult<ElderlyExtraCheckInTabDO> pageResult = service.findPage(reqVO);
        return success(BeanUtils.toBean(pageResult, CheckInTabRespVO.class));
    }

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

}
