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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.elderly.vo.ElderlyRestraintPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.elderly.vo.ElderlyRestraintRespVO;
import cn.iocoder.yudao.module.system.controller.admin.elderly.vo.ElderlyRestraintSaveReqVO;
import cn.iocoder.yudao.module.system.service.elderly.ElderlyRestraintService;
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-restraint")
@Validated
public class ElderlyRestraintController {

    @Resource
    private ElderlyRestraintService elderlyRestraintService;

    @PostMapping("/create")
    @Operation(summary = "创建约束观察记录")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyRestraintSaveReqVO createReqVO) {
        createReqVO.setTenantId(Objects.isNull(createReqVO.getTenantId())
                ? TenantContextHolder.getTenantId() : createReqVO.getTenantId());
        return success(elderlyRestraintService.create(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新约束观察记录")
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyRestraintSaveReqVO updateReqVO) {
        updateReqVO.setTenantId(Objects.isNull(updateReqVO.getTenantId())
                ? TenantContextHolder.getTenantId() : updateReqVO.getTenantId());
        elderlyRestraintService.update(updateReqVO);
        return success(Boolean.TRUE);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除约束观察记录")
    @Parameter(name = "id", description = "记录编号", required = true)
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        elderlyRestraintService.delete(id);
        return success(Boolean.TRUE);
    }

    @GetMapping("/get")
    @Operation(summary = "获得约束观察记录")
    @Parameter(name = "id", description = "记录编号", required = true, example = "1024")
    public CommonResult<ElderlyRestraintRespVO> get(@RequestParam("id") Long id) {
        return success(elderlyRestraintService.get(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得约束观察记录分页")
    public CommonResult<PageResult<ElderlyRestraintRespVO>> getPage(@Valid ElderlyRestraintPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds())
                ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        return success(elderlyRestraintService.getPage(pageReqVO));
    }
}

