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.diaperusagerecod.ElderlyDiaperUsageRecodPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.diaperusagerecod.ElderlyDiaperUsageRecodRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.diaperusagerecod.ElderlyDiaperUsageRecodSaveReqVO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyDiaperUsageRecodService;
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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 尿不湿使用记录")
@RestController
@RequestMapping("/elderly-diaper-usage-recod")
@Validated
public class ElderlyDiaperUsageRecodController {

    @Resource
    private ElderlyDiaperUsageRecodService elderlyDiaperUsageRecodService;

    @PostMapping("/create")
    @Operation(summary = "创建尿不湿使用记录")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyDiaperUsageRecodSaveReqVO createReqVO) {
        if (createReqVO.getTenantId() == null) {
            createReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyDiaperUsageRecodService.create(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新尿不湿使用记录")
    @TenantIgnore
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyDiaperUsageRecodSaveReqVO updateReqVO) {
        if (updateReqVO.getTenantId() == null) {
            updateReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        elderlyDiaperUsageRecodService.update(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除尿不湿使用记录")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        elderlyDiaperUsageRecodService.delete(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得尿不湿使用记录详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @TenantIgnore
    public CommonResult<ElderlyDiaperUsageRecodRespVO> get(@RequestParam("id") Long id) {
        return success(elderlyDiaperUsageRecodService.get(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得尿不湿使用记录分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyDiaperUsageRecodRespVO>> page(@Valid ElderlyDiaperUsageRecodPageReqVO pageReqVO) {
        if (pageReqVO.getTenantIds() == null) {
            pageReqVO.setTenantIds(new Long[]{TenantContextHolder.getTenantId()});
        }
        return success(elderlyDiaperUsageRecodService.getPage(pageReqVO));
    }
}
