package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.exception.ApiException;
import com.cool.store.request.FranchiseeSaveRequest;
import com.cool.store.request.InitiatingRequest;
import com.cool.store.request.IntentAgreementSubmitRequest;
import com.cool.store.response.InitiatingResponse;
import com.cool.store.response.ResponseResult;
import com.cool.store.response.SigningBaseInfoResponse;
import com.cool.store.service.IntentAgreementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping({"/pc/IntentAgreement"})
@Slf4j
@Api(tags = "PC意向协议")
public class PCIntentAgreementController {

    @Resource
    IntentAgreementService intentAgreementService;

    @GetMapping(path = "/get")
    @ApiOperation("查询意向协议信息")
    public ResponseResult<SigningBaseInfoResponse> getMiniIntentAgreement(
            @RequestParam(value = "partnerId", required = false) String partnerId,
            @RequestParam(value = "lineId", required = false) Long lineId) {
        SigningBaseInfoResponse resp = intentAgreementService.getMiniIntentAgreement(partnerId, lineId);
        return ResponseResult.success(resp);
    }

    @PostMapping(path = "/initiating")
    @ApiOperation("kdz -> xfsg 发起意向协议流程")
    public ResponseResult initiating(@RequestBody IntentAgreementSubmitRequest request) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(intentAgreementService.initiating(request,user));
    }

    @PostMapping(path = "/franchisee/save")
    @ApiOperation("kdz -> xfsg 加盟商新增")
    public ResponseResult save(@RequestBody FranchiseeSaveRequest request) throws ApiException {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return intentAgreementService.save(request,user);
    }



    @GetMapping(path = "/getOaDetail")
    @ApiOperation("oa数据回显")
    public ResponseResult<InitiatingRequest> getOaDetail(@RequestParam("mobile") String mobile,
                                      @RequestParam("idCardNo") String idCardNo) {
        return ResponseResult.success(intentAgreementService.getOaDetail(mobile,idCardNo));
    }

    @ApiOperation("跳过意向协议")
    @GetMapping("/skipIntentAgreement")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", value = "线索id", required = true)
    })
    public ResponseResult<Boolean> skipIntentAgreement(@RequestParam("lineId")Long lineId) {
        return ResponseResult.success(intentAgreementService.skipIntentAgreement(lineId,CurrentUserHolder.getUser()));
    }


}
