package cn.iocoder.yudao.module.system.controller.admin.biz;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ElderlyTempOutCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ElderlyTempOutPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ElderlyTempOutRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ElderlyTempOutUpdateReqVO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyTempOutService;
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.Objects;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 离住记录")
@RestController
@RequestMapping("/elderly/temp-out")
@Validated
public class ElderlyTempOutController {

    @Resource
    private ElderlyTempOutService elderlyTempOutService;

    @PostMapping("/create")
    @Operation(summary = "创建离住记录")
    @TenantIgnore
    public CommonResult<Boolean> create(@Valid @RequestBody ElderlyTempOutCreateReqVO createReq) {
        createReq.setTenantId(createReq.getTenantId() == null ? TenantContextHolder.getTenantId() : createReq.getTenantId());
        elderlyTempOutService.create(createReq);
        return success(true);
    }

    @PostMapping("/edit")
    @Operation(summary = "编辑离住记录")
    @TenantIgnore
    public CommonResult<Boolean> edit(@Valid @RequestBody ElderlyTempOutUpdateReqVO updateReq) {
        elderlyTempOutService.update(updateReq);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除离住记录")
    @Parameter(name = "id", description = "离住记录ID", required = true, example = "1024")
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        elderlyTempOutService.delete(id);
        return success(true);
    }

    @GetMapping("/findPage")
    @Operation(summary = "离住记录分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyTempOutRespVO>> findPage(@Valid ElderlyTempOutPageReqVO reqVO) {
        reqVO.setTenantIds(Objects.isNull(reqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : reqVO.getTenantIds());
        return success(elderlyTempOutService.page(reqVO));
    }

    @GetMapping("/getDetail")
    @Operation(summary = "离住记录详情")
    @Parameter(name = "id", description = "离住记录ID", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<ElderlyTempOutRespVO> getDetail(@RequestParam("id") Long id) {
        return success(elderlyTempOutService.get(id));
    }
}

