package com.xunmei.system.api;

import com.xunmei.common.core.constant.SecurityConstants;
import com.xunmei.common.core.constant.ServiceNameConstants;
import com.xunmei.common.core.domain.R;
import com.xunmei.system.api.domain.SysUser;
import com.xunmei.system.api.factory.RemoteUserFallbackFactory;
import com.xunmei.system.api.model.LoginUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 用户服务
 *
 * @author xunmei
 */
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService {
    /**
     * 通过用户名查询用户信息
     *
     * @param username 用户名
     * @param source   请求来源
     * @return 结果
     */
    @GetMapping("/user/info/{username}")
    public R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/user/getUserById")
    public SysUser getUserById(@RequestParam("id") Long id, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 通过用户名查询用户信息
     *
     * @param source 请求来源
     * @return 结果
     */
    @PostMapping("/user/sync/list")
    public R<List<SysUser>> getAllSyncUser(@RequestBody SysUser request, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);


    /**
     * 批量保存同步用户
     *
     * @param userList
     * @param source   userList
     * @return
     */
    @PostMapping("/user/sync/batch")
    public R<Boolean> batchSaveSyncUser(@RequestBody List<SysUser> userList, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 记录用户最后一次登录信息
     * @param loginTime
     * @param loginIp
     * @param source
     * @return
     */
    @PostMapping("/user/userLoginInfo")
    R<Boolean> userLoginInfo(@RequestParam("id") Long id,@RequestParam("loginTime") Date loginTime,@RequestParam("loginIp") String loginIp,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

}
