package com.gree.mall.manager.controller.settle.repair;

import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.annotation.ZfireList;
import com.gree.mall.manager.bean.settle.repair.DailyWithholdVO;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.settle.repair.DailyWithholdLogic;
import com.gree.mall.manager.plus.entity.SettleDailyWithhold;
import com.gree.mall.manager.plus.entity.SysDictCompany;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@Slf4j
@RestController
@Api(value = "维修日结算扣款配置API", tags = {"维修日结算扣款配置API"})
@RequestMapping(value = "/daily/withhold", produces = "application/json; charset=utf-8")
@RequiredArgsConstructor
public class DailyWithholdController {

    private final DailyWithholdLogic dailyWithholdLogic;

    @ZfireList
    @PostMapping("/list")
    @ApiOperation(value = "列表")
    public ResponseHelper<IPage<DailyWithholdVO>> page(
            @RequestBody ZfireParamBean zfireParamBean
    ) {
        IPage<DailyWithholdVO> page = dailyWithholdLogic.page(zfireParamBean);
        return ResponseHelper.success(page, new TypeReference<DailyWithholdVO>() {
        });
    }


    @PostMapping("/detail")
    @ApiOperation("详情")
    public ResponseHelper<SettleDailyWithhold> detail(
            @ApiParam(required = true) @RequestParam String id
    ){
        SettleDailyWithhold detail = dailyWithholdLogic.detail(id);
        return ResponseHelper.success(detail);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public ResponseHelper add(
            @RequestBody SettleDailyWithhold dailyWithhold
    ){
        dailyWithholdLogic.add(dailyWithhold);
        return ResponseHelper.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public ResponseHelper update(
            @RequestBody SettleDailyWithhold dailyWithhold
    ){
        dailyWithholdLogic.update(dailyWithhold);
        return ResponseHelper.success();
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public ResponseHelper delete(
            @ApiParam(required = true, value = "id") @RequestParam String id
    ){
        dailyWithholdLogic.delete(id);
        return ResponseHelper.success();
    }

    @PostMapping("/config/get")
    @ApiOperation(value = "获取结算汇总暂扣款比例")
    public ResponseHelper<SysDictCompany> getConfig()
    {
        SysDictCompany dict = dailyWithholdLogic.getConfig();
        return ResponseHelper.success(dict);
    }

    @PostMapping("/config/save")
    @ApiOperation(value = "配置结算汇总暂扣款比例")
    public ResponseHelper saveConfig(
            @ApiParam(required = true, value = "10%请传0.1") @RequestParam BigDecimal rate) {
        dailyWithholdLogic.saveConfig(rate);
        return ResponseHelper.success();
    }

    @GetMapping("/config/getbyCode")
    @ApiOperation(value = "获取结算发放/查询手机号列表")
    public ResponseHelper<List<SysDictCompany>> getConfigByCode(
            @ApiParam(required = true, value = "查询： SELECT,发放：ISSUE") @RequestParam String code
    )
    {
        List<SysDictCompany> dict = dailyWithholdLogic.getConfig(code);
        return ResponseHelper.success(dict);
    }
}
