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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ElderlyFixedExpenseAppendReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ExpenseRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ExpenseSaveReqVO;
import cn.iocoder.yudao.module.system.service.biz.ExpenseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

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

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


@Tag(name = "管理后台 - 长者费用记录")
@RestController
@RequestMapping("/elderly/expense")
@Validated
public class ExpenseController {

    @Resource
    private ExpenseService expenseService;


    @PostMapping("/createExpense")
    @Operation(summary = "创建入住办理")
    public CommonResult<Long> createExpense(@Valid @RequestBody ExpenseSaveReqVO createReqVO) {
        return success(expenseService.createExpense(createReqVO));
    }


    @GetMapping("/get")
    @Operation(summary = "入住办理详情")
    @Parameter(name = "elderId", description = "长者ID", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<ExpenseRespVO> getExpense(@RequestParam("elderId") Long elderId,@RequestParam(value = "contractId",required = false) Long contractId) {
        ExpenseRespVO expense = expenseService.getExpense(elderId,contractId);
        return success(expense);
    }


    @PostMapping("/renewContract")
    @Operation(summary = "续签")
    @TenantIgnore
    @PermitAll
    public CommonResult<Boolean> renewContract(@RequestBody ExpenseSaveReqVO createReqVO){
        expenseService.renewContract(createReqVO);
        return success(true);
    }


    @PostMapping("/addFixedExpense")
    @Operation(summary = "给长者追加固定费用")
    @TenantIgnore
    public CommonResult<Boolean> addFixedExpense(@Valid @RequestBody ElderlyFixedExpenseAppendReqVO reqVO) {
        expenseService.appendFixedExpense(reqVO);
        return success(true);
    }


//
//    @PutMapping("/update")
//    @Operation(summary = "更新长者费用记录")
//    @PreAuthorize("@ss.hasPermission('elderly:expense:update')")
//    public CommonResult<Boolean> updateExpense(@Valid @RequestBody ExpenseSaveReqVO updateReqVO) {
//        expenseService.updateExpense(updateReqVO);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete")
//    @Operation(summary = "删除长者费用记录")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('elderly:expense:delete')")
//    public CommonResult<Boolean> deleteExpense(@RequestParam("id") Long id) {
//        expenseService.deleteExpense(id);
//        return success(true);
//    }
//

//
//    @GetMapping("/page")
//    @Operation(summary = "获得长者费用记录分页")
//    @PreAuthorize("@ss.hasPermission('elderly:expense:query')")
//    public CommonResult<PageResult<ExpenseRespVO>> getExpensePage(@Valid ExpensePageReqVO pageReqVO) {
//        PageResult<ExpenseDO> pageResult = expenseService.getExpensePage(pageReqVO);
//        return success(BeanUtils.toBean(pageResult, ExpenseRespVO.class));
//    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出长者费用记录 Excel")
//    @PreAuthorize("@ss.hasPermission('elderly:expense:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportExpenseExcel(@Valid ExpensePageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<ExpenseDO> list = expenseService.getExpensePage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "长者费用记录.xls", "数据", ExpenseRespVO.class,
//                        BeanUtils.toBean(list, ExpenseRespVO.class));
//    }

}