package com.red.circle.other.inner.endpoint.user.device.api;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.inner.model.cmd.user.device.ArchiveDeviceQryCmd;
import com.red.circle.other.inner.model.cmd.user.device.DeviceRegisterQuantityQryCmd;
import com.red.circle.other.inner.model.cmd.user.device.PageLatestMobileDeviceQryCmd;
import com.red.circle.other.inner.model.dto.user.UserLatestDeviceAssociatedDTO;
import com.red.circle.other.inner.model.dto.user.UserLatestMobileDeviceHistoryDTO;
import com.red.circle.other.inner.model.dto.user.device.ArchiveDeviceDTO;
import com.red.circle.other.inner.model.dto.user.device.DeviceRegisterQuantityDTO;
import com.red.circle.other.inner.model.dto.user.device.LatestMobileDeviceDTO;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 登记设备相关.
 *
 * @author pengliang on 2023/5/24
 */
public interface RegisterDeviceClientApi {

  String API_PREFIX = "/register-device/client";

  /**
   * 是否存在，封禁设备.
   *
   * @param deviceNo 设备号
   * @return true 存在，false 不存在
   */
  @GetMapping("/archive/exists")
  ResultResponse<Boolean> existsArchiveDevice(@RequestParam("deviceNo") String deviceNo,
      @RequestParam("sysOrigin") String sysOrigin);

  /**
   * 添加，封禁设备.
   */
  @PostMapping("/archive/add")
  ResultResponse<Void> addArchiveDevice(@RequestBody ArchiveDeviceDTO cmd);

  /**
   * 移除，封禁设备.
   */
  @PostMapping("/archive/remove")
  ResultResponse<Void> removeArchiveDevice(@RequestBody ArchiveDeviceDTO cmd);

  /**
   * 删除设备
   */
  @GetMapping("/delByDeviceNo")
  ResultResponse<Void> delByDeviceNo(@RequestParam("id") Long id);

  /**
   * 上传最新设备.
   */
  @PostMapping("/upload/latest/device/async")
  ResultResponse<Void> uploadLatestDeviceNoAsync(
      @RequestBody LatestMobileDeviceDTO cmd);

  /**
   * 获取用户设备号.
   *
   * @param userId 用户id
   * @return 设备编码
   */
  @GetMapping("/user/device")
  ResultResponse<String> getImeiByUserId(@RequestParam("userId") Long userId);

  /**
   * 获取设备注册用户.
   */
  @GetMapping("/imei/user")
  ResultResponse<List<Long>> listUserIdByImei(@RequestParam("imei") String imei,
      @RequestParam("sysOrigin") String sysOrigin);

  /**
   * 获取设备注册用户.
   */
  @GetMapping("/listByImei")
  ResultResponse<List<UserLatestMobileDeviceHistoryDTO>> listByImei(
      @RequestParam("imei") String imei,
      @RequestParam("sysOrigin") String sysOrigin);

  /**
   * 获取用户最新登记设备关联用户id.
   */
  @GetMapping("/listLatestAssociationUserIds")
  ResultResponse<List<Long>> listLatestAssociationUserIds(@RequestParam("userId") Long userId);

  /**
   * 根据用户id获得关联ip与设备的用户id集合.
   *
   * @param userId 用户ID
   * @return 用户ID
   */
  @GetMapping("/getIpOrImeiUserId")
  ResultResponse<Set<Long>> getIpOrImeiUserId(@RequestParam("userId") Long userId);

  /**
   * 根据userId获得设备信息
   *
   * @param userId 用户id
   * @return 设备信息
   */
  @GetMapping("/getDeviceByUserId")
  ResultResponse<UserLatestDeviceAssociatedDTO> getDeviceByUserId(
      @RequestParam("userId") Long userId);

  /**
   * 获取设备最新信息分页结果
   */
  @PostMapping("/pageLatestMobileDevice")
  ResultResponse<PageResult<UserLatestMobileDeviceHistoryDTO>> pageLatestMobileDevice(
      @RequestBody PageLatestMobileDeviceQryCmd query);

  /**
   * 获取注册设备数量映射.
   */
  @PostMapping("/mapDeviceRegisterQuantity")
  ResultResponse<Map<String, DeviceRegisterQuantityDTO>> mapDeviceRegisterQuantity(
      @RequestBody DeviceRegisterQuantityQryCmd cmd);

  /**
   * 设备号
   *
   * @param userIds 用户
   * @return 设备信息
   */
  @PostMapping("/mapImeiByIds")
  ResultResponse<Map<Long, String>> mapImeiByIds(@RequestBody Set<Long> userIds);

  /**
   * 分页查询设备
   */
  @PostMapping("/pageList")
  ResultResponse<PageResult<ArchiveDeviceDTO>> pageList(@RequestBody ArchiveDeviceQryCmd query);

  /**
   * 获取用户设备指纹（唯一标识）
   * 
   * @param userId 用户ID
   * @return 设备指纹字符串，由 device_type|request_client|phone_model|ip 拼接而成
   */
  @GetMapping("/user/device/fingerprint")
  ResultResponse<String> getDeviceFingerprintByUserId(@RequestParam("userId") Long userId);

  /**
   * 检查当前用户的设备指纹是否与其他主播用户共享
   * 
   * @param userId 用户ID
   * @return true-存在共享设备的主播用户, false-不存在
   */
  @GetMapping("/user/device/fingerprint/check-anchor")
  ResultResponse<Boolean> checkDeviceFingerprintHasAnchor(@RequestParam("userId") Long userId);
}
