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.common.util.object.BeanUtils;
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.*;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.RefundSettlementOrderDO;
import cn.iocoder.yudao.module.system.service.biz.RefundSettlementOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.security.access.prepost.PreAuthorize;
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.Objects;

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


@Tag(name = "管理后台 - 长者退住结算单")
@RestController
@RequestMapping("/elderly/refundSettlementOrder")
@Validated
public class RefundSettlementOrderController {

    @Resource
    private RefundSettlementOrderService refundSettlementOrderService;


    //    @PostMapping("/create")
//    @Operation(summary = "创建长者退住结算单")
//    public CommonResult<Long> createRefundSettlementOrder(@Valid @RequestBody RefundSettlementOrderSaveReqVO createReqVO) {
//        return success(refundSettlementOrderService.createRefundSettlementOrder(createReqVO));
//    }
//
//    @PutMapping("/update")
//    @Operation(summary = "更新长者退住结算单")
//    @PreAuthorize("@ss.hasPermission('elderly:refund-settlement-order:update')")
//    public CommonResult<Boolean> updateRefundSettlementOrder(@Valid @RequestBody RefundSettlementOrderSaveReqVO updateReqVO) {
//        refundSettlementOrderService.updateRefundSettlementOrder(updateReqVO);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete")
//    @Operation(summary = "删除长者退住结算单")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('elderly:refund-settlement-order:delete')")
//    public CommonResult<Boolean> deleteRefundSettlementOrder(@RequestParam("id") Long id) {
//        refundSettlementOrderService.deleteRefundSettlementOrder(id);
//        return success(true);
//    }
//
//    @GetMapping("/getRefundSettlementOrder")
//    @Operation(summary = "获得长者退住结算详情")
//    @Parameter(name = "id", description = "退住结算单ID", required = true, example = "1024")
//    @TenantIgnore
//    public CommonResult<RefundSettlementOrderRespVO> getRefundSettlementOrder(@RequestParam("id") Long id) {
////        RefundSettlementOrderRespVO refundSettlementOrder = refundSettlementOrderService.getRefundSettlementOrder(id);
//        return success( refundSettlementOrderService.getRefundSettlementOrder(id));
//    }

//    @GetMapping("/getRefundSettlementOrderDetails")
//    @Operation(summary = "获得长者退住详情")
//    @Parameter(name = "id", description = "退住结算单ID", required = true, example = "1024")
//    @TenantIgnore
//    public CommonResult<RefundSettlementOrderRespVO> getRefundSettlementOrderDetails(@RequestParam("id") Long id) {
//        RefundSettlementOrderRespVO refundSettlementOrder = refundSettlementOrderService.getRefundSettlementOrderDetails(id);
//        return success(refundSettlementOrder);
//    }

    @GetMapping("/getRefundSettlementOrderPage")
    @Operation(summary = "获得长者退住结算单分页")
    @TenantIgnore
    public CommonResult<PageResult<RefundSettlementOrderDO>> getRefundSettlementOrderPage(@Valid RefundSettlementOrderPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<RefundSettlementOrderDO> pageResult = refundSettlementOrderService.getRefundSettlementOrderPage(pageReqVO);
        return success(pageResult);
    }






    @PostMapping("refundSupplementarySettlement")
    @Operation(summary = "补充结算")
    @TenantIgnore
    public CommonResult<Boolean> refundSupplementarySettlement(@RequestBody RefundSupplementarySettlementSaveReqVO saveReqVO){
        refundSettlementOrderService.refundSupplementarySettlement(saveReqVO);
        return success(true);
    }


    @GetMapping("/getRefundSupplementarySettlement")
    @Operation(summary = "补充结算详情")
    @TenantIgnore
    public CommonResult<RefundSupplementarySettlementRespVO> getRefundSupplementarySettlement(@RequestParam("refundSettlementOrderId") Long refundSettlementOrderId){
        return success(refundSettlementOrderService.getRefundSupplementarySettlement(refundSettlementOrderId));
    }


//    @GetMapping("/getVirtualRefundSettlementOrder")
//    @Operation(summary = "获得退住结算详情(虚拟账单)")
//    @TenantIgnore
//    public CommonResult<RefundSettlementOrderRespVO> getVirtualRefundSettlementOrder(@RequestParam("id") Long id) {
//        RefundSettlementOrderRespVO refundSettlementOrder = refundSettlementOrderService.getVirtualRefundSettlementOrder(id);
//        return success(refundSettlementOrder);
//    }
//

    @GetMapping("/getRefundSettlementOrder")
    @Operation(summary = "获得退住单结算详情")
    @TenantIgnore
    public CommonResult<RefundSettlementOrderRespVO> getRefundSettlementOrder(@RequestParam("id") Long id) {
        RefundSettlementOrderRespVO refundSettlementOrder = refundSettlementOrderService.getRefundSettlementOrder(id);
        return success(refundSettlementOrder);
    }


    @PostMapping("/editRefundSettlementOrder")
    @Operation(summary = "编辑退住单结算详情")
    @TenantIgnore
    public CommonResult<Boolean> editRefundSettlementOrder(@RequestBody RefundSettlementOrderRespVO respVO ){
        refundSettlementOrderService.editRefundSettlementOrder(respVO);
        return success(true);
    }



    @PostMapping("/settleVirtualRefundOrder")
    @Operation(summary = "虚拟账单结算")
    @TenantIgnore
    public CommonResult<Boolean> settleVirtualRefundOrder(@RequestBody ExpensePayOrderSaveReqVO saveReqVO) {
        refundSettlementOrderService.settleVirtualRefundOrder(saveReqVO);
        return success(true);
    }


    @GetMapping("/getSettledRefundOrderDetail")
    @Operation(summary = "获取已结算退住订单详情")
    @TenantIgnore
    public CommonResult<RefundSettledOrderDetailVO> getSettledRefundOrderDetail(@RequestParam("id") Long id) {
        return success(refundSettlementOrderService.getSettledRefundOrderDetail(id));
    }


//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出长者退住结算单 Excel")
//    @PreAuthorize("@ss.hasPermission('elderly:refund-settlement-order:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportRefundSettlementOrderExcel(@Valid RefundSettlementOrderPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<RefundSettlementOrderDO> list = refundSettlementOrderService.getRefundSettlementOrderPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "长者退住结算单.xls", "数据", RefundSettlementOrderRespVO.class,
//                        BeanUtils.toBean(list, RefundSettlementOrderRespVO.class));
//    }

}