package com.fzm.mall.customer.service.customer.controller;


import com.fzm.mall.customer.service.customer.entity.dto.CustomerDTO;
import com.fzm.mall.customer.service.customer.entity.dto.CustomerSaveDTO;
import com.fzm.mall.customer.service.customer.entity.dto.ShopCustomerDTO;
import com.fzm.mall.customer.service.customer.service.CustomerService;
import com.fzm.mall.customer.service.repo.ResponseFactory;
import com.fzm.mall.customer.service.repo.ResponseVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wulixian
 * @since 2021-04-07
 */
@Api(tags = "客服中心")
@RestController
@RequestMapping("/customerService")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CustomerServiceController {

    private final CustomerService customerService;
    private final ResponseFactory resFac;

    @ApiOperation(value = "客服中心-联系客服")
    @ApiOperationSupport(order = 1)
    @PostMapping("/contact")
    public ResponseVO contact(@RequestBody @Valid CustomerSaveDTO customerSaveDTO) {

        CustomerDTO result = customerService.contact(customerSaveDTO);
        return resFac.getSuccessResponseWithData(result);
    }

    @ApiOperation(value = "客服中心-获取聊天列表")
    @ApiOperationSupport(order = 2)
    @GetMapping("/list")
    public ResponseVO list(@ApiParam(value = "用户id", required = true) @RequestParam String userId,
                           @ApiParam(value = "聊天事id") @RequestParam(required = false) String toId,
                           @ApiParam(value = "搜索关键词") @RequestParam(required = false) String keyWord) {
        List<CustomerDTO> result = customerService.list(userId, toId, keyWord);
        return resFac.getSuccessResponseWithData(result);
    }

    @ApiOperation(value = "客服中心-获取店铺客服列表")
    @ApiOperationSupport(order = 2)
    @GetMapping("/listShopCustomer")
    public ResponseVO list(@ApiParam(value = "商家id", required = true) @RequestParam String merchantId) {
        List<ShopCustomerDTO> result = customerService.listShopCustomer(merchantId);
        return resFac.getSuccessResponseWithData(result);
    }
}
