package com.goafanti.customer.controller;

import com.goafanti.common.bo.Error;
import com.goafanti.common.bo.Result;
import com.goafanti.common.controller.BaseApiController;
import com.goafanti.common.model.Admin;
import com.goafanti.common.model.AdminCallDay;
import com.goafanti.core.mybatis.page.Pagination;
import com.goafanti.core.shiro.token.TokenManager;
import com.goafanti.customer.bo.InputCallNumber;
import com.goafanti.customer.bo.InputListCallDayBo;
import com.goafanti.customer.bo.InputUserCallList;
import com.goafanti.customer.service.UserOutboundService;
import com.goafanti.customer.service.impl.AdminCallDayService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/api/admin/userOutbound")
public class UserOutboundApiController  extends BaseApiController {

    @Resource
    private UserOutboundService userOutboundService;
    @Resource
    private AdminCallDayService adminCallDayService;

    /**
     * 客户外呼查询
     *
     */
    @PostMapping("/checkUser")
    public Result checkUser(Integer type) {
        return new Result<>().data(this.userOutboundService.checkUser(type));
    }


    /**
     * 坐席点击呼叫
     *
     */
    @PostMapping("/callNumber")
    public Result callNumber(InputCallNumber in) {
        Result res =new Result();
        Admin adminToken = TokenManager.getAdminToken();
        String callNo = null;
        if (adminToken != null) {
            callNo = adminToken.getCallNo();
            in.setAgent(callNo);
        }
        if (in.getAgent()==null){
            return res.error(new Error("坐席号不能为空"));
        }
        if (in.getCallee()==null){
            return res.error(new Error("客户号码不能为空"));
        }
        if (in.getUid()==null){
            return res.error(new Error("客户编号不能为空"));
        }

        return this.userOutboundService.pushCallNumber(in);
    }

    /**
     * 坐席呼叫转移
     *
     */
    @PostMapping("/blindTransferByAgent")
    public Result blindTransferByAgent(InputCallNumber in) {
        Result res =new Result();
        Admin adminToken = TokenManager.getAdminToken();
        String callNo = null;
        if (adminToken != null) {
            callNo = adminToken.getCallNo();
            in.setAgent(callNo);
        }
        if (in.getAgent()==null){
            return res.error(new Error("坐席号不能为空"));
        }
        if (in.getTransAgent()==null){
            return res.error(new Error("转移坐席号不能为空"));
        }
        return  userOutboundService.blindTransferByAgent(in);
    }

    /**
     * 坐席列表
     *
     */
    @GetMapping("/agentList")
    public Result agentList() {
        return new Result<>().data(this.userOutboundService.agentList());
    }


    /**
     * 获取默认电话
     *
     */
    @GetMapping("/getDefaultMobile")
    public Result getDefaultMobile(String uid) {
        return new Result<>().data(this.userOutboundService.getDefaultMobile(uid));
    }


    /**
     * 通话记录
     *
     */
    @GetMapping("/userCallList")
    public Result userCallList(InputUserCallList in) {
        return new Result<>().data(this.userOutboundService.userCallList(in));
    }

    /**
     * 所有通话记录查询
     *
     */
    @GetMapping("/callAllList")
    public Result callAllList(InputUserCallList in) {
        return new Result<>().data(this.userOutboundService.callAllList(in));
    }


    /**
     * 外呼明细
     *
     */
    @GetMapping("/listCallDay")
    public Result<Pagination<AdminCallDay>> listCallDay(InputListCallDayBo in) {
        return new Result<>().data(this.adminCallDayService.listCallDay(in));
    }
}
