import 'dart:io';

import 'package:dio/dio.dart' hide Headers;
import 'package:retrofit/retrofit.dart';
import 'package:sport/bean/UpdateInfo.dart';
import 'package:sport/bean/comment.dart';
import 'package:sport/bean/comment_post.dart';
import 'package:sport/bean/feedback_category.dart';
import 'package:sport/bean/forum.dart';
import 'package:sport/bean/game.dart';
import 'package:sport/bean/game_record.dart';
import 'package:sport/bean/game_record_sum.dart';
import 'package:sport/bean/image.dart';
import 'package:sport/bean/notice.dart';
import 'package:sport/bean/post.dart';
import 'package:sport/bean/rank_game_info.dart';
import 'package:sport/bean/rank_info.dart';
import 'package:sport/bean/share_info.dart';
import 'package:sport/bean/shop.dart';
import 'package:sport/bean/sport_detail.dart';
import 'package:sport/bean/sport_index.dart';
import 'package:sport/bean/sport_step.dart';
import 'package:sport/bean/sport_target.dart';
import 'package:sport/bean/sport_target_index.dart';
import 'package:sport/bean/sport_target_record.dart';
import 'package:sport/bean/sport_target_today.dart';
import 'package:sport/bean/user_friend.dart';
import 'package:sport/bean/user_info.dart';
import 'package:sport/services/api/resp.dart';
import 'package:sport/bean/message.dart';

part 'rest_client.g.dart';

@RestApi()
abstract class RestClient {
  factory RestClient(Dio dio, {String baseUrl}) = _RestClient;

  @GET("/app/checkUpdate")
  Future<RespData<UpdateInfo>> checkUpdate(@Query("version") String version);

  @GET("/user/info")
  Future<RespData<UserInfo>> getUserInfo(@Query("id") String uid, {@DioOptions() Options options});

  @GET("/user/countNameCard")
  Future<RespData<int>> getCountNameCard();

  // ********************** 运动首页相关 *****************************
  @GET("/sport/index")
  Future<RespData<SportIndex>> getSportIndex();

  @GET("/sport/detail")
  Future<RespData<SportDetail>> getSportDetail();

  @POST("/sportRecord/addGame")
  Future<RespList<SportTarget>> postAddGame(
      @Query("game_id") int gameId,
      @Query("score") double score,
      @Query("duration") int duration,
      @Query("consume") int consume,
      @Query("screen") int screen,
      @Query("jump_count") int jumpCount,
      @Query("crouch_count") int crouchCount,
      @Query("step_count") int stepCount,
      @Query("distance") int distance);

  @GET("/sportTarget/all")
  Future<RespList<SportTarget>> getSportTargetAll();

  @GET("/sportTarget/setold")
  Future<RespData<SportTargetToday>> setSportTarget(@Query("id") int id);

  @GET("/sportTarget/set")
  Future<RespData<SportTargetToday>> setSportTargetToday(@Query("type") String type,{@Query("consume") int consume, @Query("duration_minute") int durationMinute});

  @GET("/sportTarget/setCustom")
  Future<RespData<SportTargetToday>> setSportTargetCustom(@Query("duration") int duration, @Query("consume") int consume);

  @GET("/sportTarget/del")
  Future<Resp> delSportTarget();

  @GET("/sportTarget/my")
  Future<RespData<SportTargetToday>> getSportTargetMy();

  @GET("/sportTarget/index")
  Future<RespData<SportTargetIndex>> getSportTargetIndex();

  @GET("/sportTarget/records")
  Future<RespList<SportTargetRecord>> getSportTargetRecord(@Query("year") int year, @Query("month") int month);

  @FormUrlEncoded()
  @POST("/sportTarget/reward")
  Future<RespData<String>>  sportTargetReward(@Query("id") int id);

  @GET("/sportRecord/listOneDay")
  Future<RespData<SportDetailSimple>> getSportRecordListOneDay(@Query("date") String date);

  @GET("/sportRecord/listByDay")
  Future<RespData<SportDetailSimple>> getSportRecordListByDay(@Query("begin") String begin, @Query("end") String end);

  @GET("/sportRecord/listByMonth")
  Future<RespData<SportDetailSimple>> getSportRecordListByMonth(@Query("year") int year);

  @GET("/sportRecord/listByYear")
  Future<RespData<SportDetailSimple>> getSportRecordListByYear();

  @GET("/sportRecord/list")
  Future<RespPage<RecordsTodaySum>> getSportRecordList(@Query("game_id") int gameId, {@Query("page") int page});

  @FormUrlEncoded()
  @POST("/stepRecord/addDaily")
  Future<RespData<SportStep>> addDaily({@Query("step") int step, @Query("distance") int distance, @Query("time") String time, @Field("data") String data});

  @GET("/stepRecord/listOneDay")
  Future<RespData<SportStep>> getStepRecordListOneDay(@Query("date") String date);

  @GET("/stepRecord/listByDay")
  Future<RespData<SportStep>> getStepRecordListByDay(@Query("begin") String begin, @Query("end") String end);

  @GET("/stepRecord/listByMonth")
  Future<RespData<SportStep>> getStepRecordListByMonth(@Query("year") int year);

  @GET("/stepRecord/listByYear")
  Future<RespData<SportStep>> getStepRecordListByYear();

  @GET("/gameRecord/sum")
  Future<RespList<GameRecordSum>> getGameRecordSum();
  @GET("/gameRecord/game")
  Future<RespData<GameRecord>> getGameRecord(@Query("id") int gameId);

  @GET("/rank/game")
  Future<RespData<RankInfo>> getRankInfo(@Query("game_id") String gameId,
      {@Query("province_id") int provinceId, @Query("city_id") int cityId, @Query("district_id") int districtId});

  // ********************** 社区相关 *****************************
  @GET("/forum/index")
  Future<RespList<Forum>> getForumIndex();

  @GET("/forum/list")
  Future<RespPage<Post>> getPostList({@Query("forumId") String forumId, @Query("p") int page, @Query("isGood") int isGood, @Query("kw") String kw ,@Query("isOfficial") String isOfficial,});

  @GET("/forum/listByOfficial")
  Future<RespPage<Post>> getPostListByOfficial({@Query("forumId") String forumId, @Query("p") int page, @Query("limit") int limit,  @Query("sortBy") String sortBy,@Query("isOfficial") String isOfficial});

  @GET("/forum/listByHot")
  Future<RespPage<Post>> getPostListByHot({@Query("forumId") String forumId,@Query("p") int page,@Query("isOfficial") String isOfficial, @DioOptions() Options options});

  @GET("/forum/listByUser")
  Future<RespPage<Post>> getPostListByUser(@Query("uid") String uid,
      {@Query("forumId") String forumId, @Query("p") int page, @Query("sortBy") String sortBy, @Query("removeTop") int removeTop,@Query("isOfficial") String isOfficial});

  @GET("/forum/listByFollow")
  Future<RespPage<Post>> getPostListByFollow(@Query("uid") String uid,  {@Query("forumId") String forumId,@Query("p") int page, @Query("limit") int limit, @Query("testuid") int testuid, @Query("sortBy") String sortBy,@Query("isOfficial") String isOfficial,@DioOptions() Options options});

  @GET("/forum/subjectDetail")
  Future<RespData<Post>> getPostDetail(@Query("subjectId") String subjectId);

  @GET("/forum/comments")
  Future<RespPage<Comment>> getPostComments(@Query("subjectId") String subjectId, {@Query("p") int page, @Query("sortBy") String sortBy});

  @GET("/forum/subComments")
  Future<RespPage<Comment>> getPostCommentSubs(@Query("parentCommentId") String parentCommentId, {@Query("p") int page, @Query("sortBy") String sortBy});

  @GET("/forum/commentsFromId")
  Future<RespList<Comment>> getPostCommentsFromId(@Query("commentId") String commentId, {@Query("limit") int limit, @Query("sortBy") String sortBy});

  @GET("/forum/hotSearchWords")
  Future<RespList<String>> getSearchWords();

  @POST("/forum/like")
  Future<RespData<String>> postForumLike(@Query("objectId") String objectId, @Query("fieldName") String fieldName);

  @POST("/forum/unlike")
  Future<RespData<String>> postForumUnLike(@Query("objectId") String objectId, @Query("fieldName") String fieldName);

  @POST("/forum/delSubject")
  Future<RespData<String>> postDelSubject(@Query("subjectId") String subjectId);

  @POST("/forum/delComment")
  Future<RespData<String>> postDelComment(@Query("commentId") String commentId);

  @POST("/forum/report")
  Future<RespData<String>> postForumReport({@Query("subjectId") String subjectId, @Query("commentId") String commentId, @Query("content") String content,@Query("userId") int userId});

  @POST("/forum/blockUser")
  Future<RespList<int>> postForumBlockUser(@Query("uid") String uid);

  @POST("/forum/unblockUser")
  Future<RespList<int>> postForumUnBlockUser(@Query("uid") String uid);

  @GET("/forum/myBlockUsers")
  Future<RespList<UserInfo>> getMyBlockUsers();

  @POST("/forum/blockObject")
  Future<RespData<String>> postForumBlockObject(@Query("objectId") String objectId, @Query("for") String forName);

  @POST("/forum/postComment")
  Future<RespData<CommentPost>> postForumComment(@Query("subjectId") String subjectId, @Query("content") String content,
      {@Query("parentCommentId") String parentCommentId, @Query("toCommentId") String toCommentId});

  @POST("/forum/post")
  Future<RespData<Map<String, dynamic>>> postForum(@Query("forumId") String forumId, @Query("content") String content,
      {@Query("images") String images,
      @Query("quoteSubjectId") String quoteSubjectId,
      @Query("quoteCommentId") String quoteCommentId,
        @Query("quoteData") String quoteData,
      CancelToken cancelToken});

  @POST("/forum/setUserTopSubjects")
  Future<RespData<String>> setUserTopSubjects(@Query("subjectIdList") String subjectIdList);

  @POST("/forum/unsetUserTopSubjects")
  Future<RespData<String>> unsetUserTopSubjects(@Query("subjectIdList") String subjectIdList);

  @GET("/forum/userTopSubjects")
  Future<RespList<Post>> getPostUserTopSubjects(@Query("uid") String uid,
      {@Query("forumId") String forumId, @Query("p") int page, @Query("sortBy") String sortBy});

  @POST("/forum/follow")
  Future<RespData<String>> userFollow({@Query("uid") int uid, @Query("groupId") String groupId, @Query("groupName") String groupName});

  @POST("/forum/unfollow")
  Future<RespData<String>> userUnFollow({@Query("uid") int uid});

  @POST("/forum/ignoreFollow")
  Future<RespData<String>> userIgnoreFollow({@Query("uid") int uid});

  @GET("/forum/followList")
  Future<RespListTest<UserFriend>> userFollowList({@Query("groupId") String groupId, @Query("kw") String kw, @Query("p") int page, @Query("limit") int limit = 50});

  @GET("/forum/fansList")
  Future<RespListTest<UserFriend>> userFansList({@Query("groupId") String groupId, @Query("kw") String kw, @Query("p") int page, @Query("limit") int limit = 50});

  @GET("/forum/friends")
  Future<RespList<UserFriend>> userFriends({@Query("groupId") String groupId, @Query("kw") String kw, @Query("p") int page, @Query("limit") int limit = 50 ,@Query("test") String test,});

  @GET("/forum/friends")
  Future<RespListTest<UserFriend>> userFriendsTest({@Query("groupId") String groupId, @Query("kw") String kw, @Query("p") int page, @Query("limit") int limit = 50 ,@Query("test") String test,});

  @GET("/user/search")
  Future<RespPage<UserInfo>> userSearch({@Query("kw") String kw, @Query("p") int page, @Query("limit") int limit = 20});

  @POST("/user/newFriendCode")
  Future<RespData> getNewFriendCode({@Query("forever") int forever, @Query("forceUpate") int forceUpdate,});


  @POST("/user/newFriend")
  Future<RespData<NewFriend>> getNewFriend(@Query("code") String code);

  @POST("/share/forwardSubject")
  Future<RespData<MessageInstance>> shareForwardSubject(@Query("subject_id") int subjectId,@Query("user_id") int userId,);


  @POST("/message/receive")
  Future<RespData<Message>> getMessageForPoll({@Query("cur_id") int curId});

  @POST("/user/FetchFriendsRequest")
  Future<RespList<UserFriend>> getFriendRequest();

  @POST("/user/RejectFriend")
  Future<RespData<bool>> postRejectFriend(@Query("uid") int uid);

  @POST("/user/AcceptFriend")
  Future<RespData> postAcceptFriend(@Query("uid") int uid);

  @POST("/user/isFriend")
  Future<RespData<bool>> postIsFriend(@Query("uid") int uid);

  // ********************** 聊天相关 *****************************

  @POST("/chat/index")
  Future<RespList<ChatMessageInstance>> getChatIndex();

  @POST("/chat/user")
  Future<RespData<ChatMessage>> getChatUser(@Query("user_id") int userId,{@Query("begin_id") int beginId});

  @POST("/chat/send")
  Future<RespData<MessageInstance>> postChatSend(@Query("user_id") int userId,@Query("type") String type,@Query("data") String data,);

  @POST("/chat/upload")
  @Headers(<String, dynamic>{
    "content-type": "multipart/form-data",
  })
  Future<RespData> postChatUpload(@Part(name: "file") File file,);

  @POST("/chat/info")
  Future<RespList<ChatOnlineInfo>> getChatUserInfo(@Query("user_ids")  List<int> userIds,);

  // ********************** 分享相关 *****************************

  @POST("/share/createSport")
  Future<RespData<ShareInfo>> getshareCreateSport(@Query("period")  String period,@Query("weight")  double weight);


  @POST("/share/forwardSport")
  Future<RespData<MessageInstance>> getshareForwardSport(@Query("h")  String hash,@Query("user_id")  int userId);
  // ********************** 公告相关 *****************************
  @GET("/inform/list")
  Future<RespPage<Notice>> getInformList({@Query("p") int page});

  @POST("/inform/read")
  Future<RespData> postInformRead(@Query("informId") int informId);

  @GET("/notice/list")
  Future<RespPage<Notice>> getNoticeList(
      {@Query("type") String type,
      @Query("markread") String markread = "currpage",
      @Query("p") int page,
      @Query("read") String read,
      @Query("isMsg") String isMsg = "1"});

  @GET("/notice/count")
  Future<RespData<int>> getNoticeCount(@Query("type") String type, @Query("read") String read, {@Query("isMsg") String isMsg = "1"});

  @POST("/notice/read")
  Future<RespData<Notice>> postNoticeRead(@Query("noticeId") int noticeId);

  // ********************** 反馈相关 *****************************

  @GET("/feedback/types")
  Future<RespList<FeedbackCategory>> getFeedbackTypes();

  @GET("/feedback/myChats")
  Future<RespList<FeedbackCategory>> getFeedbackChat({@Query("groupId") int groupId, @Query("typeId") int typeId});

  @POST("/feedback/post")
  Future<RespData<String>> postFeedback(@Query("typeId") int typeId, @Query("content") String content,
      {@Query("images") String images, @Query("extra") String extra});

  @POST("/media/Up4Feedback")
  @Headers(<String, dynamic>{
    "content-type": "multipart/form-data",
  })
  Future<RespData<String>> mediaUp4Feedback(@Part(name: "media") File file);

  @POST("/media/Up4Subject")
  @Headers(<String, dynamic>{
    "content-type": "multipart/form-data",
  })
  Future<RespData<Image>> mediaUp4Subject(@Part(name: "media") File file,
      {@Query("srcType") String srcType, @Query("subjectId") String subjectId, CancelToken cancelToken});

  // ********************** 游戏相关 *********************************
  @GET("/game/all")
  Future<RespList<GameInfoData>> getGameAll();

  @GET("/game/all")
  Future getGameById(@Query("id") int id);

  @GET("/rank/all")
  Future<RespList<RankInfoData>> getRankInfoAll();

  @GET("/rank/game")
  Future<RespData<RankGameInfoData>> getRankGameInfo(@Query("game_id") String id,
      {@Query("scope") String scope});

  @GET("/rank/sport")
  Future<RespData<RankGameInfoData>> getRankSportInfo(@Query("rank_id") String id,
      {@Query("scope") String scope});

// ********************** 商城相关 *********************************

  @GET("/shop/item")
  Future<RespData<ShopIndex>> getShopIndex();

  @GET("/score/record")
  Future<RespData<ScoreList>> getScoreIndex();

  @POST("/shop/buy")
  Future<RespData<String>> buyItem(@Query("item_id") String id,);
}
