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.elderlyactivity.ElderlyActivityRecordPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlyactivity.ElderlyActivityRecordRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlyactivity.ElderlyActivityRecordSaveReqVO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyActivityRecordService;
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;

/**
 * 管理后台 - 长者楼层活动记录 Controller
 *
 * @author 系统管理员
 */
@Tag(name = "管理后台 - 长者楼层活动记录")
@RestController
@RequestMapping("/elderly-activity-record")
@Validated
public class ElderlyActivityRecordController {

    @Resource
    private ElderlyActivityRecordService elderlyActivityRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建长者楼层活动记录")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyActivityRecordSaveReqVO createReqVO) {
        // tenantId 可由前端传；不传则默认当前租户
        if (createReqVO.getTenantId() == null) {
            createReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyActivityRecordService.createElderlyActivityRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新长者楼层活动记录")
    @TenantIgnore
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyActivityRecordSaveReqVO updateReqVO) {
        if (updateReqVO.getTenantId() == null) {
            updateReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        elderlyActivityRecordService.updateElderlyActivityRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除长者楼层活动记录")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        elderlyActivityRecordService.deleteElderlyActivityRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得长者楼层活动记录详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @TenantIgnore
    public CommonResult<ElderlyActivityRecordRespVO> get(@RequestParam("id") Long id) {
        return success(elderlyActivityRecordService.getElderlyActivityRecord(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得长者楼层活动记录分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyActivityRecordRespVO>> page(@Valid ElderlyActivityRecordPageReqVO pageReqVO) {
        // tenantId 可由前端传；不传则默认当前租户
        if (pageReqVO.getTenantId() == null) {
            pageReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyActivityRecordService.getElderlyActivityRecordPage(pageReqVO));
    }
}
