package com.ym.mec.web.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.service.ImUserFriendService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("imUserFriend")
@Api(tags = "IM通讯录")
@RestController
public class ImUserFriendController extends BaseController {

	@Autowired
	private ImUserFriendService imUserFriendService;

	@Autowired
	private SysUserFeignService sysUserFeignService;

	@ApiOperation("添加好友")
	@PostMapping(value = "/add")
	@ApiImplicitParams({ @ApiImplicitParam(name = "memo", value = "备注", required = true, dataType = "String"),
			@ApiImplicitParam(name = "nickname", value = "昵称", required = true, dataType = "String"),
			@ApiImplicitParam(name = "friendUserId", value = "好友编号", required = true, dataType = "Integer")})
	public Object addFriend(Integer friendUserId, String nickname, String memo) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		return succeed(imUserFriendService.addFriend(sysUser.getId(),friendUserId,nickname,memo));
	}

	@ApiOperation("删除好友")
	@PostMapping(value = "/del")
	@ApiImplicitParams({ @ApiImplicitParam(name = "friendUserId", value = "好友编号", required = true, dataType = "Integer")})
	public Object quitGroup(Integer friendUserId) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		return succeed(imUserFriendService.deleteFriend(sysUser.getId(),friendUserId));
	}

	@ApiOperation("修改昵称，备注")
	@PostMapping(value = "/updateFriend")
	@ApiImplicitParams({ @ApiImplicitParam(name = "memo", value = "备注", required = true, dataType = "String"),
			@ApiImplicitParam(name = "nickname", value = "昵称", required = true, dataType = "String"),
			@ApiImplicitParam(name = "friendUserId", value = "好友编号", required = true, dataType = "Integer")})
	public Object updateFriend(Integer friendUserId, String nickname, String memo) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		return succeed(imUserFriendService.updateFriendNickname(sysUser.getId(),friendUserId,nickname,memo));
	}
}
