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.OutboundRefundConfigPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ExpenseSubsidyDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.OutboundRefundConfigDO;
import cn.iocoder.yudao.module.system.service.biz.OutboundRefundConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;

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

import java.util.List;

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


@Tag(name = "管理后台 - 外出退费配置")
@RestController
@RequestMapping("/elderly/outboundRefundConfig")
@Validated
public class OutboundRefundConfigController {

    @Resource
    private OutboundRefundConfigService outboundRefundConfigService;

    @PostMapping("/create")
    @Operation(summary = "创建外出退费配置")
    @TenantIgnore
    public CommonResult<Long> createOutboundRefundConfig(@Valid @RequestBody OutboundRefundConfigDO createReqVO) {
        createReqVO.setTenantId(createReqVO.getTenantId() == null ? TenantContextHolder.getTenantId() : createReqVO.getTenantId());
        return success(outboundRefundConfigService.createOutboundRefundConfig(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新外出退费配置")
    @TenantIgnore
    public CommonResult<Boolean> updateOutboundRefundConfig(@Valid @RequestBody OutboundRefundConfigDO updateReqVO) {
        outboundRefundConfigService.updateOutboundRefundConfig(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除外出退费配置")
    @Parameter(name = "id", description = "配置ID", required = true)
    @TenantIgnore
    public CommonResult<Boolean> deleteOutboundRefundConfig(@RequestParam("id") Long id) {
        outboundRefundConfigService.deleteOutboundRefundConfig(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得外出退费配置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<OutboundRefundConfigDO> getOutboundRefundConfig(@RequestParam("id") Long id) {
        return success(outboundRefundConfigService.getOutboundRefundConfig(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得外出退费配置分页")
    @TenantIgnore
    public CommonResult<PageResult<OutboundRefundConfigDO>> getOutboundRefundConfigPage(@Valid OutboundRefundConfigPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(pageReqVO.getTenantIds() == null ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<OutboundRefundConfigDO> pageResult = outboundRefundConfigService.getOutboundRefundConfigPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/findList")
    @Operation(summary = "获取外出退费配置列表")
    @TenantIgnore
    public CommonResult<List<OutboundRefundConfigDO>> findList(@RequestParam(value = "tenantIds",required = false) Long[] tenantIds){
        tenantIds = tenantIds == null ? new Long[]{TenantContextHolder.getTenantId()} : tenantIds;
        return success(outboundRefundConfigService.findList(tenantIds));
    }

}