package com.fs.app.controller;


import com.fs.app.annotation.Login;
import com.fs.common.core.domain.ResponseResult;
import com.fs.qw.param.newparam.ContactTagListParam;
import com.fs.qw.param.newparam.ExternalContactPageListParam;
import com.fs.qw.service.IQwExternalContactService;
import com.fs.qw.service.IQwTagService;
import com.fs.qw.vo.QwTagVO;
import com.fs.qw.vo.newvo.ExternalContactDetailsVO;
import com.fs.qw.vo.newvo.ExternalContactListVO;
import com.fs.qw.vo.newvo.ExternalContactPageVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "企微用户相关接口")
@RestController
@RequestMapping("/app/company/user")
public class QwCompanyUserController extends AppBaseController {

    @Autowired
    private IQwExternalContactService qwExternalContactService;

    @Autowired
    private IQwTagService tagService;

    @Login
    @GetMapping("/pageList")
    @ApiOperation("会员分页列表")
    public ResponseResult<PageInfo<ExternalContactListVO>> pageList(ExternalContactPageListParam param) {
        param.setUserId(Long.parseLong(getUserId()));
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<ExternalContactListVO> list = qwExternalContactService.externalContactPageList(param);
        PageInfo<ExternalContactListVO> pageInfo = new PageInfo<>(list);
        return ResponseResult.ok(pageInfo);
    }

    @Login
    @GetMapping("/totalNumber")
    @ApiOperation("会员数量统计")
    public ResponseResult<ExternalContactPageVO> getTotalNumber() {
        ExternalContactPageVO contactNumber = qwExternalContactService.getContactNumber(Long.parseLong(getUserId()));
        return ResponseResult.ok(contactNumber);
    }

    @Login
    @GetMapping("/details")
    @ApiOperation("会员详情")
    public ResponseResult<ExternalContactDetailsVO> getUserDetails(@ApiParam(value = "外部联系人id", required = true) @RequestParam Long contactId,
                                                                   @ApiParam(value = "时间tab，不传表示查询全部，分别是：今天、昨天、前天、近七天", required = true) @RequestParam String dateTag) {
        return ResponseResult.ok(qwExternalContactService.getUserDetails(Long.parseLong(getUserId()), contactId, dateTag));
    }

    @Login
    @GetMapping("/tagList")
    @ApiOperation("会员标签列表")
    public ResponseResult<PageInfo<QwTagVO>> getTagList(ContactTagListParam param) {
        param.setUserId(Long.parseLong(getUserId()));
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<QwTagVO> tagList = tagService.getTagListByUserId(param);
        PageInfo<QwTagVO> pageInfo = new PageInfo<>(tagList);
        return ResponseResult.ok(pageInfo);
    }

    @Login
    @PostMapping("/disabled")
    @ApiOperation("批量禁用会员")
    public ResponseResult<Boolean> disabledUser(@ApiParam(value = "联系人id集合", required = true) @RequestBody String[] ids) {
        Boolean r = qwExternalContactService.disabledUser(ids, false);
        return ResponseResult.ok(r);
    }

    @Login
    @PostMapping("/enabled")
    @ApiOperation("批量启用会员")
    public ResponseResult<Boolean> enabledUser(@ApiParam(value = "联系人id集合", required = true) @RequestBody String[] ids) {
        Boolean r = qwExternalContactService.disabledUser(ids, true);
        return ResponseResult.ok(r);
    }


}
