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.dal.dataobject.biz.ExpenseItemDO;
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 java.util.List;

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);
    }

    @PostMapping("/deleteExpenseItems")
    @Operation(summary = "长者删除固定费用")
    @TenantIgnore
    public CommonResult<Boolean> deleteExpenseItems(@RequestBody List<Long> expenseItemIdList) {
        expenseService.deleteExpenseItems(expenseItemIdList);
        return success(true);
    }

    @GetMapping("/getExpenseItemsByElderId")
    @Operation(summary = "获取长者所有固定费用")
    @TenantIgnore
    public CommonResult<List<ExpenseItemDO>> getExpenseItemsByElderId(@RequestParam("elderId") Long elderId) {
        return success(expenseService.getExpenseItemsByElderId(elderId));
    }

    @PostMapping("/updateExpenseItems")
    @Operation(summary = "长者更新固定费用")
    @TenantIgnore
    public CommonResult<Boolean> updateExpenseItems(@RequestBody ExpenseItemDO updateItem){
        expenseService.updateExpenseItems(updateItem);
        return success(true);
    }
}