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

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.controller.admin.yk.vo.FundedElderlyInfoPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.yk.vo.FundedElderlyInfoRespVO;
import cn.iocoder.yudao.module.system.controller.admin.yk.vo.FundedElderlyInfoSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.yk.YkFundedElderlyInfoDO;
import cn.iocoder.yudao.module.system.service.yk.FundedElderlyInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.validation.constraints.NotEmpty;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import java.util.List;

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


@Tag(name = "管理后台 - 自费长者信息")
@RestController
@Validated
public class FundedElderlyInfoController {

    @Resource
    private FundedElderlyInfoService fundedElderlyInfoService;

    @PostMapping("/ykCenter/self-funded/add")
    @Operation(summary = "创建自费长者信息")
    @TenantIgnore
    public CommonResult<Long> createFundedElderlyInfo(@RequestBody YkFundedElderlyInfoDO createReqVO) {
        return success(fundedElderlyInfoService.createFundedElderlyInfo(createReqVO));
    }

    @PutMapping("/ykCenter/self-funded/update")
    @Operation(summary = "更新自费长者信息")
    @TenantIgnore
    public CommonResult<Boolean> updateFundedElderlyInfo(@Valid @RequestBody FundedElderlyInfoSaveReqVO updateReqVO) {
        fundedElderlyInfoService.updateFundedElderlyInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/ykCenter/self-funded/delete")
    @Operation(summary = "删除自费长者信息")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> deleteFundedElderlyInfo(@RequestParam("id") Long id) {
        fundedElderlyInfoService.deleteFundedElderlyInfo(id);
        return success(true);
    }

    @GetMapping("/ykCenter/self-funded/get")
    @Operation(summary = "获得自费长者信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<FundedElderlyInfoRespVO> getFundedElderlyInfo(@RequestParam("id") Long id) {
        YkFundedElderlyInfoDO fundedElderlyInfo = fundedElderlyInfoService.getFundedElderlyInfo(id);
        return success(BeanUtils.toBean(fundedElderlyInfo, FundedElderlyInfoRespVO.class));
    }

    @GetMapping("/ykCenter/self-funded/list")
    @Operation(summary = "获得自费长者信息分页")
    @TenantIgnore
    public CommonResult<PageResult<FundedElderlyInfoRespVO>> getFundedElderlyInfoPage(@Valid FundedElderlyInfoPageReqVO pageReqVO) {
        PageResult<YkFundedElderlyInfoDO> pageResult = fundedElderlyInfoService.getFundedElderlyInfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, FundedElderlyInfoRespVO.class));
    }

    @DeleteMapping("/ykCenter/self-funded/batch-delete")
    @Operation(summary = "批量删除自费长者")
    @TenantIgnore
    public CommonResult<Boolean> batchDeleteFundedElderlyInfo(@RequestBody @NotEmpty(message = "ID列表不能为空") List<Long> ids) {
        fundedElderlyInfoService.batchDeleteFundedElderlyInfo(ids);
        return success(true);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出自费长者信息 Excel")
//    @PreAuthorize("@ss.hasPermission('self:funded-elderly-info:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportFundedElderlyInfoExcel(@Valid FundedElderlyInfoPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<FundedElderlyInfoDO> list = fundedElderlyInfoService.getFundedElderlyInfoPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "自费长者信息.xls", "数据", FundedElderlyInfoRespVO.class,
//                        BeanUtils.toBean(list, FundedElderlyInfoRespVO.class));
//    }

}