package com.clx.performance.controller.feign;

import com.clx.open.sdk.request.action.BreakContractSettlementGenerateAction;
import com.clx.performance.param.feign.OrderAdjustTonnageDownParam;
import com.clx.performance.param.pc.owner.OwnerConfirmBreakContractSettlementParam;
import com.clx.performance.service.breakcontract.BreakContractOwnerRecordService;
import com.clx.performance.service.breakcontract.BreakContractOwnerRuleService;
import com.clx.performance.service.breakcontract.BreakContractSettlementOwnerService;
import com.clx.performance.vo.pc.breakcontract.carrier.BreakContractOwnerRuleVO;
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.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping(value="/feign/breakContract")
@Validated
@Tag(name = "货主违约结算单")
@AllArgsConstructor
public class BreakContractSettlementOwnerFeignController {

    private final BreakContractSettlementOwnerService breakContractSettlementOwnerService;

    private final BreakContractOwnerRuleService breakContractOwnerRuleService;

    private final BreakContractOwnerRecordService breakContractOwnerRecordService;




    @Operation(summary = "货主订单吨数下调自动保存违约结算单")
    @PostMapping("/saveSettlementOwnerForTonnageDown")
    Result<Void> saveBreakContractSettlementOwner(@RequestBody @Validated OrderAdjustTonnageDownParam param){
        breakContractSettlementOwnerService.saveSettlementOwnerForTonnageDown(param);
        return Result.ok();
    }

    @Operation(summary = "查询货主违约规则")
    @GetMapping("/getRuleInfo")
    Result<BreakContractOwnerRuleVO> getRuleInfo(@RequestParam Integer id){
        return Result.ok(breakContractOwnerRuleService.getRuleInfo(id));
    }

    @Operation(summary = "货主客户端货主确认生成违约结算单")
    @PostMapping("/updateBreakContract")
    Result updateBreakContract(@RequestBody @Validated BreakContractSettlementGenerateAction param){
        OwnerConfirmBreakContractSettlementParam settlementParam = new OwnerConfirmBreakContractSettlementParam();
        settlementParam.setConfirmStatus(param.getConfirmStatus());
        settlementParam.setId(param.getBreakContractId());
        settlementParam.setRejectReason(param.getRejectReason());
        breakContractOwnerRecordService.updateConfirmStatus(settlementParam);
        return Result.ok();
    }

}
