package com.xunhong.erp.turbo.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.xunhong.erp.turbo.api.biz.api.ExpenseRecordServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.ExpenseRecordCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.ExpenseRecordUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.ExpenseRecordListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.ExpenseRecordShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.ExpenseRecordVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author shenyifei
 */
@Tag(name = "ExpenseRecord", description = "花销统计记录管理")
@RestController("operationExpenseRecordController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class ExpenseRecordController {

	@DubboReference(version = "1.0.0")
    private final ExpenseRecordServiceI expenseRecordService;

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_EXPENSE_RECORD_VIEW})
    @GetMapping("listExpenseRecord")
    @Operation(summary = "花销统计记录列表", method = "GET")
    public MultiResponse<ExpenseRecordVO> listExpenseRecord(@ModelAttribute @Validated ExpenseRecordListQry expenseRecordListQry) {
        return MultiResponse.of(expenseRecordService.list(expenseRecordListQry));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_EXPENSE_RECORD_CREATE})
    @PostMapping("createExpenseRecord")
    @Operation(summary = "创建花销统计记录", method = "POST")
    public SingleResponse<ExpenseRecordVO> createExpenseRecord(@RequestBody @Validated ExpenseRecordCreateCmd expenseRecordCreateCmd) {
        return SingleResponse.of(expenseRecordService.create(expenseRecordCreateCmd));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_EXPENSE_RECORD_VIEW})
    @GetMapping("showExpenseRecord")
    @Operation(summary = "花销统计记录详情", method = "GET")
    public SingleResponse<ExpenseRecordVO> showExpenseRecord(@ModelAttribute @Validated ExpenseRecordShowQry expenseRecordShowQry) {
        return SingleResponse.of(expenseRecordService.show(expenseRecordShowQry));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_EXPENSE_RECORD_UPDATE})
    @RequestMapping(value = "updateExpenseRecord", method = {RequestMethod.PATCH, RequestMethod.PUT})
    @Operation(summary = "花销统计记录更新", method = "PATCH")
    public SingleResponse<ExpenseRecordVO> updateExpenseRecord(@RequestBody @Validated ExpenseRecordUpdateCmd expenseRecordUpdateCmd) {
        return SingleResponse.of(expenseRecordService.update(expenseRecordUpdateCmd));
    }
}
