package com.clx.performance.controller.pc.breakcontract.carrier;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.param.pc.breakcontract.carrier.BreakContractOwnerRuleAddParam;
import com.clx.performance.param.pc.breakcontract.carrier.BreakContractOwnerRuleStatusUpdateParam;
import com.clx.performance.param.pc.breakcontract.carrier.PageBreakContractOwnerRuleParam;
import com.clx.performance.service.breakcontract.BreakContractOwnerRuleService;
import com.clx.performance.vo.pc.breakcontract.carrier.BreakContractOwnerRuleFileVO;
import com.clx.performance.vo.pc.breakcontract.carrier.BreakContractOwnerRulePullDownVO;
import com.clx.performance.vo.pc.breakcontract.carrier.BreakContractOwnerRuleVO;
import com.msl.common.base.PageData;
import com.msl.common.convertor.aspect.UnitCovert;
import com.msl.common.enums.ResultCodeEnum;
import com.msl.common.exception.ServiceSystemException;
import com.msl.common.result.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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


@Slf4j
@RestController
@RequestMapping(value="/pc/carrier/breakContract/ownerRule")
@Validated
@Tag(name = "承运端-货主违约规则")
@AllArgsConstructor
public class CarrierBreakContractOwnerRuleController {

    private final BreakContractOwnerRuleService breakContractOwnerRuleService;

    @Operation(summary = "新增货主违约规则", description = "<br>By:艾庆国")
    @PostMapping("/saveRule")
    @UnitCovert
    public Result<Void> saveRule(@RequestBody @Validated BreakContractOwnerRuleAddParam param) {
        if (StringUtils.isBlank(param.getRule().get("A-a"))){throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER);};
        if (StringUtils.isBlank(param.getRule().get("A-b"))){throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER);};
        if (StringUtils.isBlank(param.getRule().get("A-c"))){throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER);};
        if (StringUtils.isBlank(param.getRule().get("A-d"))){throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER);};
        if (StringUtils.isBlank(param.getRule().get("A-e"))){throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER);};

        breakContractOwnerRuleService.saveRule(param);

        return Result.ok();
    }

    @Operation(summary = "更新状态", description = "<br>By:艾庆国")
    @PostMapping("/updateStatus")
    public Result<Void> updateStatus(@RequestBody @Validated BreakContractOwnerRuleStatusUpdateParam param) {
        breakContractOwnerRuleService.updateStatus(param);

        return Result.ok();
    }

    @Operation(summary = "查询规则详情", description = "<br>By:艾庆国")
    @GetMapping("/getRuleInfo")
    @UnitCovert(param = false)
    public Result<BreakContractOwnerRuleVO> getRuleInfo(Integer id) {

        return Result.ok(breakContractOwnerRuleService.getRuleInfo(id));
    }

    @Operation(summary = "查询规则文档信息", description = "<br>By:艾庆国")
    @GetMapping("/getRuleFile")
    public Result<BreakContractOwnerRuleFileVO> getRuleFile(Integer id) {

        return Result.ok(breakContractOwnerRuleService.getRuleFile(id));
    }

    @Operation(summary = "分页搜索违约列表",description = "<br>By:艾庆国")
    @PostMapping("/pageRule")
    @UnitCovert(param = false)
    public Result<PageData<BreakContractOwnerRuleVO>> pageRule(@RequestBody @Validated PageBreakContractOwnerRuleParam param) {
        IPage<BreakContractOwnerRuleVO> page = breakContractOwnerRuleService.pageRule(param);
        return Result.page(page.getRecords(), page.getTotal(), page.getPages());
    }

    @Operation(summary = "查询方案下拉列表",description = "<br>By:艾庆国")
    @PostMapping("/listPullDown")
    public Result<List<BreakContractOwnerRulePullDownVO>> listPullDown() {
        return Result.ok(breakContractOwnerRuleService.listPullDown());
    }

}
