package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.dto.TransferLogDTO;
import com.cool.store.enums.point.PayBusinessTypeEnum;
import com.cool.store.request.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.LinePayService;
import com.cool.store.service.LineService;
import com.cool.store.service.TransferLogService;
import com.cool.store.vo.*;
import com.github.pagehelper.PageInfo;
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;

/**
 * @Author suzhuhong
 * @Date 2024/3/27 15:57
 * @Version 1.0
 */
@RestController
@RequestMapping("/pc/line")
@Api(tags = "PC线索信息")
@Slf4j
public class LineInfoController {

    @Resource
    LineService lineService;
    @Resource
    TransferLogService transferLogService;
    @Resource
    private LinePayService linePayService;

    @ApiOperation("查询线索详情")
    @GetMapping("/getLineDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", value = "线索id", required = true)
    })
    public ResponseResult<LineInfoVO> getLineInfo(@RequestParam("lineId")Long lineId) {
        return ResponseResult.success(lineService.getLineInfo(lineId));
    }

    @ApiOperation("我的线索")
    @PostMapping("/getMyLineList")
    public ResponseResult<PageInfo<LineListVO>> getLineList(@RequestBody LineListRequest lineListRequest) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(lineService.getLineList(lineListRequest,user,Boolean.FALSE));
    }

    @ApiOperation("团队线索")
    @PostMapping("/getTeamLineList")
    public ResponseResult<PageInfo<LineListVO>> getTeamLineList(@RequestBody LineListRequest lineListRequest) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(lineService.getLineList(lineListRequest,user,Boolean.TRUE));
    }

    @ApiOperation("公海线索")
    @PostMapping("/getPublicLineList")
    public ResponseResult<PageInfo<PublicLineListVO>> getPublicLineList(@RequestBody PublicLineListRequest publicLineListRequest) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(lineService.getPublicLineList(publicLineListRequest,user,Boolean.TRUE));
    }

    @ApiOperation("待分配线索")
    @PostMapping("/getAssignedLineList")
    public ResponseResult<PageInfo<PublicLineListVO>> getAssignedLineList(@RequestBody PublicLineListRequest publicLineListRequest) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(lineService.getPublicLineList(publicLineListRequest,user,Boolean.FALSE));
    }

    @ApiOperation("我负责的加盟商")
    @PostMapping("/getPartnerList")
    public ResponseResult<PageInfo<PartnerListVO>> getPartnerList(@RequestBody PartnerRequest partnerRequest) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(lineService.getPartnerList(partnerRequest,user,Boolean.FALSE));
    }

    @ApiOperation("团队的加盟商")
    @PostMapping("/getTeamPartnerList")
    public ResponseResult<PageInfo<PartnerListVO>> getTeamPartnerList(@RequestBody PartnerRequest partnerRequest) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(lineService.getPartnerList(partnerRequest,user,Boolean.TRUE));
    }

    @PostMapping(path = "/addTags")
    @ApiOperation("添加标签接口")
    public ResponseResult<Boolean> addTags(@RequestBody AddTagsRequest addTagsRequest){
        return ResponseResult.success(lineService.addTags(CurrentUserHolder.getUser(),addTagsRequest));
    }

    @ApiOperation("分配招商经理")
    @PostMapping("/distributionInvestmentManager")
    public ResponseResult<Boolean> distributionInvestmentManager(@RequestBody ChangeInvestmentRequest changeInvestmentRequest) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(lineService.transferInvestmentManager(changeInvestmentRequest,user,Boolean.FALSE));
    }

    @ApiOperation("转让")
    @PostMapping("/transferInvestmentManager")
    public ResponseResult<Boolean> transferInvestmentManager(@RequestBody ChangeInvestmentRequest changeInvestmentRequest) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(lineService.transferInvestmentManager(changeInvestmentRequest,user,Boolean.TRUE));
    }

    @ApiOperation("线索转让记录")
    @GetMapping("/getTransferLogPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", value = "线索id", required = true),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "大小", required = true)
    })
    public ResponseResult<PageInfo<TransferLogDTO>> getTransferLogPage(@RequestParam("lineId")Long lineId,
                                                                 @RequestParam(value = "pageNum" ,defaultValue = "1")Integer pageNum,
                                                                 @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize) {
        return ResponseResult.success(transferLogService.getTransferLogPage(pageNum,pageSize,lineId));
    }

    @ApiOperation("查询意向金详情")
    @GetMapping("/getLinePayInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", value = "线索id", required = true)
    })
    public ResponseResult<LinePayVO> getLinePayInfo(@RequestParam("lineId")Long lineId) {
        return ResponseResult.success(linePayService.getLinePayInfo(lineId, PayBusinessTypeEnum.INTENT_MONEY.getCode(),null));
    }

    @ApiOperation("线索流程进度")
    @GetMapping("/getIntendProcess")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", value = "线索id", required = true)
    })
    public ResponseResult<IntendProcessTotalVO> getIntendProcessTotal(@RequestParam("lineId")Long lineId) {
        return ResponseResult.success(lineService.getIntendProcessTotal(lineId));
    }

    @ApiOperation("新建线索")
    @PostMapping("/addLine")
    public ResponseResult<Boolean> addLine(@RequestBody AddLineRequest addLineRequest) {
        return ResponseResult.success(lineService.addLine(addLineRequest,CurrentUserHolder.getUser()));
    }


    @ApiOperation("修改线索信息")
    @PostMapping("/changeLineInfo")
    public ResponseResult<Boolean> changeLineInfo(@RequestBody UpdateLineRequest updateLineRequest) {
        return ResponseResult.success(lineService.changeLineInfo(updateLineRequest,CurrentUserHolder.getUser()));
    }

    @ApiOperation("将线索从未分配转为已分配")
    @PostMapping("/distributionLine")
    public ResponseResult<Boolean> distributionLine(@RequestBody DistributionInvestmentRequest distributionInvestmentRequest) {
        return ResponseResult.success(lineService.distributionLine(distributionInvestmentRequest,CurrentUserHolder.getUser()));
    }

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


}
