package cn.superdesk.uniorder.controller.operationCenter.customer;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dto.param.operationCenter.customer.OpCenterCustomerOperatorOrgParam;
import cn.superdesk.uniorder.dto.param.operationCenter.customer.OperationCenterCustomerParam;
import cn.superdesk.uniorder.dto.param.operationCenter.customer.OperationCenterCustomerSaveParam;
import cn.superdesk.uniorder.dto.vo.operationCenter.base.OperationCenterVo;
import cn.superdesk.uniorder.dto.vo.operationCenter.customer.OperationCenterCustomerVo;
import cn.superdesk.uniorder.dto.vo.operationCenter.customer.OperationCenterPaymentCustomerVo;
import cn.superdesk.uniorder.dubbo.consumer.operationCenter.customer.OperationCenterCustomerDubboService;
import com.alibaba.fastjson2.JSON;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author : zx
 * @Create : 2023/4/11 09:44
 * Description : PC端客户管理模块的接口
 */

@Api(value = "运营中心-客户管理", tags = {"数据管理-客户管理"})
@Slf4j
@RestController
@RequestMapping("/operationCenter/customer")
@RequiredArgsConstructor
public class OperationCenterCustomerController extends BaseController {
    private final OperationCenterCustomerDubboService operationCenterCustomerDubboService;
    /**
     * 列表
     */
    @PostMapping("/list")
    public R<List<OperationCenterCustomerVo>> list( @RequestBody @Validated OperationCenterCustomerParam param) {
        log.info("运营中心--客户管理-列表：入参：param:{}", JSON.toJSONString(param));
        return operationCenterCustomerDubboService.getOperationCenterCustomerList(param);
    }


    /**
     * 新增 修改
     */
    @PostMapping("/addOrUpdate")
    public R<String> addOrUpdate(@Validated @RequestBody OperationCenterCustomerSaveParam param) {
        log.info("运营中心--客户管理-新增 或修改 ：入参：param:{}", JSON.toJSONString(param));
       return operationCenterCustomerDubboService.saveOperationCenterCustomer(param,getToken());

    }


    /**
     * 根据id查询客户信息
     */
    @PostMapping("/get/{id}")
    public R<OperationCenterCustomerVo> get(@PathVariable("id") Long id) {
        log.info("运营中心--客户管理-根据id查询客户信息--->入参：id:{}", id);
        return operationCenterCustomerDubboService.getOperationCenterCustomerById(id);

    }

    /**
     * 删除
     */
    @PostMapping("/delete/{id}")
    public R<String> delete(@PathVariable("id") Long id) {
        log.info("运营中心--客户管理-根据id软删除客户信息--->入参：id:{}", id);
        return operationCenterCustomerDubboService.deleteOperationCenterCustomerById(id);

    }
    /**
     * 支付方式 关联客户列表--> 包含已删除的
     */
    @PostMapping("/selectAll")
    public R<List<OperationCenterPaymentCustomerVo>> selectAll(@RequestBody @Validated OperationCenterCustomerParam param) {
        log.info("运营中心--支付方式配置-添加指定客户列表：入参：param:{}", JSON.toJSONString(param));
        return operationCenterCustomerDubboService.findAll(param);

    }
    /**
     * 客户下拉列表-不含已删除
     */
    @PostMapping("/select")
    public R<List<OperationCenterVo>> select() {
        return operationCenterCustomerDubboService.selectAllCustomerIdAndName();
    }
    /**
     * 客户关联-运营商-项目
     */
    @PostMapping("/linkOperatorAndOrg")
    public R<String> linkOperatorAndOrg(@RequestBody @Validated OpCenterCustomerOperatorOrgParam param) {
        log.info("运营中心--添加-添加指定客户：入参：param:{}", JSON.toJSONString(param));
        return operationCenterCustomerDubboService.linkOperatorAndOrg(param,getToken());

    }
    /**
     * 客户关联-运营商-项目 根据客户id查询
     */
    @PostMapping("/linkOperatorAndOrg/{customerId}")
    public R<OpCenterCustomerOperatorOrgParam> linkOperatorAndOrgByCustomerId(@PathVariable("customerId") String customerId) {
        return operationCenterCustomerDubboService.linkOperatorAndOrgByCustomerId(customerId);

    }


}
