import 'package:flutter/cupertino.dart';
import 'package:yumi/app/constants/sc_room_msg_type.dart';
import 'package:yumi/shared/business_logic/models/req/sc_give_away_gift_room_acceptscmd.dart';
import 'package:yumi/shared/business_logic/models/res/gift_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_is_follow_room_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_mic_go_up_res.dart';
import 'package:yumi/shared/business_logic/models/res/mic_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_contribute_level_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_join_black_list_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_red_packet_detail_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_red_packet_grab_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_red_packet_list_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_reward_info_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_rocket_config_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_rocket_status_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_task_list_res.dart';
import 'package:yumi/shared/business_logic/models/res/user_count_guard_res.dart';
import 'package:yumi/ui_kit/widgets/room/room_msg_item.dart';
import 'package:provider/provider.dart';

import 'package:yumi/shared/business_logic/models/res/sc_banner_leaderboard_res.dart';
import 'package:yumi/shared/business_logic/models/res/gift_backpack_res.dart';
import 'package:yumi/shared/business_logic/models/res/gift_by_group_res.dart';
import 'package:yumi/shared/business_logic/models/res/login_res.dart';
import 'package:yumi/shared/business_logic/models/res/my_room_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_emoji_res.dart';
import 'package:yumi/shared/business_logic/models/res/room_gift_rank_res.dart';
import 'package:yumi/shared/business_logic/models/res/room_member_res.dart';
import 'package:yumi/shared/business_logic/models/res/room_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_room_task_claimable_count_res.dart';
import 'package:yumi/shared/business_logic/models/res/room_user_card_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_violation_handle_res.dart';
import 'package:yumi/shared/business_logic/repositories/room_repository.dart';
import 'package:yumi/services/audio/rtm_manager.dart';
import 'package:yumi/shared/data_sources/sources/remote/net/network_client.dart';
import 'package:yumi/shared/tools/sc_room_profile_cache.dart';

class SCChatRoomRepository implements SocialChatRoomRepository {
  static SCChatRoomRepository? _instance;

  SCChatRoomRepository._internal();

  factory SCChatRoomRepository() {
    return _instance ??= SCChatRoomRepository._internal();
  }

  bool _isBrokenLocalMediaUrl(String? url) {
    return (url ?? "").contains("/external/oss/local/");
  }

  bool _shouldHydrateRoomProfile(String? roomId, String? roomCover) {
    return (roomId ?? "").trim().isNotEmpty &&
        ((roomCover ?? "").trim().isEmpty || _isBrokenLocalMediaUrl(roomCover));
  }

  Future<SocialChatRoomRes> _hydrateRoomRes(SocialChatRoomRes room) async {
    final cachedRoom = SCRoomProfileCache.applyToSocialChatRoomRes(room);
    if (!_shouldHydrateRoomProfile(cachedRoom.id, cachedRoom.roomCover)) {
      return cachedRoom;
    }
    debugPrint(
      "[Room Cover][room-list] hydrate roomId=${cachedRoom.id} remoteCover=${cachedRoom.roomCover ?? ""}",
    );
    final specificRoom = await specific(cachedRoom.id ?? "");
    debugPrint(
      "[Room Cover][room-list] specific roomId=${cachedRoom.id} specificCover=${specificRoom.roomCover ?? ""}",
    );
    return SCRoomProfileCache.applyToSocialChatRoomRes(
      cachedRoom.copyWith(
        roomCover: SCRoomProfileCache.preferNonEmpty(
          specificRoom.roomCover,
          cachedRoom.roomCover,
        ),
        roomName: SCRoomProfileCache.preferNonEmpty(
          specificRoom.roomName,
          cachedRoom.roomName,
        ),
        roomDesc: SCRoomProfileCache.preferNonEmpty(
          specificRoom.roomDesc,
          cachedRoom.roomDesc,
        ),
      ),
    );
  }

  ///room/live-voice/discovery
  @override
  Future<List<SocialChatRoomRes>> discovery({bool? allRegion}) async {
    Map<String, dynamic> queryParams = {};
    if (allRegion != null) {
      queryParams["allRegion"] = allRegion;
    }
    final result = await http.get(
      "363603111e51beac2d183014dd29b81ced652239ec13178acd7001096cab7429",
      queryParams: queryParams,
      fromJson:
          (json) =>
              (json as List).map((e) => SocialChatRoomRes.fromJson(e)).toList(),
    );
    return Future.wait(result.map(_hydrateRoomRes));
  }

  ///live/mic/list
  @override
  Future<List<MicRes>> micList(String roomId) async {
    Map<String, dynamic> queryParams = {};
    queryParams["roomId"] = roomId;
    final result = await http.get(
      "b1d6a1284f5ddeaa1cbb1430f2991e8a",
      queryParams: queryParams,
      fromJson:
          (json) => (json as List).map((e) => MicRes.fromJson(e)).toList(),
    );
    return result;
  }

  ///room/profile/specific
  @override
  Future<MyRoomRes> specific(String roomId) async {
    Map<String, dynamic> queryParams = {};
    queryParams["roomId"] = roomId;
    final result = await http.get<MyRoomRes>(
      "08c7cb961a83d24c9e0d4b11d7af3f0a8f2fe5ccf18a5ca6a0caf80ecefaeb02",
      queryParams: queryParams,
      fromJson: (json) => MyRoomRes.fromJson(json),
    );
    debugPrint(
      "[Room Cover][specific] roomId=${result.id ?? roomId} roomCover=${result.roomCover ?? ""} roomName=${result.roomName ?? ""}",
    );
    await SCRoomProfileCache.saveRoomProfile(
      roomId: result.id ?? roomId,
      roomCover: result.roomCover,
      roomName: result.roomName,
      roomDesc: result.roomDesc,
    );
    return SCRoomProfileCache.applyToMyRoomRes(result);
  }

  ///room/relation/status
  @override
  Future<SCIsFollowRoomRes> isFollowRoom(String roomId) async {
    Map<String, dynamic> queryParams = {};
    queryParams["roomId"] = roomId;
    final result = await http.get(
      "1c9e38f372be8ae5afde3a37710c24815dee9b62b097054c3e40e333e7747681",
      queryParams: queryParams,
      fromJson: (json) => SCIsFollowRoomRes.fromJson(json),
    );
    return result;
  }

  ///room/contribution/level
  @override
  Future<SCRoomContributeLevelRes> contributeLevel(String roomId) async {
    Map<String, dynamic> queryParams = {};
    queryParams["roomId"] = roomId;
    final result = await http.get(
      "730cfe8ab28a5bb6b75adb2d29320bd85285ddc5a507f997b1c6a23980d22a70",
      queryParams: queryParams,
      fromJson: (json) => SCRoomContributeLevelRes.fromJson(json),
    );
    return result;
  }

  ///activity/room-contribution-activity
  @override
  Future<SCRoomContributeLevelRes> roomContributionActivity(
    String roomId,
  ) async {
    Map<String, dynamic> queryParams = {};
    queryParams["roomId"] = roomId;
    final result = await http.get(
      "fe8a114454bb0a64c51b5a2840b89b9caad8e1b76b3e1c570f21d856505cee7d1621a5cc87df186c3e223af28d3b4455",
      queryParams: queryParams,
      fromJson: (json) => SCRoomContributeLevelRes.fromJson(json),
    );
    return result;
  }

  ///live/mic/go-up
  @override
  Future<SCMicGoUpRes> micGoUp(
    String roomId,
    num mickIndex, {
    String? eventType,
    String? inviterId,
  }) async {
    Map<String, dynamic> params = {};
    params["roomId"] = roomId;
    params["mickIndex"] = mickIndex;
    if (eventType != null) {
      params["eventType"] = eventType;
    }
    if (inviterId != null) {
      params["inviterId"] = inviterId;
    }
    final result = await http.post<SCMicGoUpRes>(
      "6fb96d680637b8e931b962f6e05260b0",
      data: params,
      fromJson: (json) => SCMicGoUpRes.fromJson(json),
    );
    return result;
  }

  ///live/mic/go-down
  @override
  Future micGoDown(String roomId, num mickIndex) async {
    final result = await http.post(
      "11335ecd55d99c9100f5cd070e5b73f1574aff257ce7e668d08f4caccd1c6232",
      data: {"roomId": roomId, "mickIndex": mickIndex},
      fromJson: (json) => null,
    );
    return result;
  }

  ///live/mic/lock
  @override
  Future micLock(String roomId, num mickIndex, bool lock) async {
    final result = await http.post(
      "70ffb9681e0103463b1faf883935e55d",
      data: {"roomId": roomId, "mickIndex": mickIndex, "lock": lock},
      fromJson: (json) => null,
    );
    return result;
  }

  ///live/mic/mute
  @override
  Future<bool> micMute(String roomId, num mickIndex, bool mute) async {
    final result = await http.post<bool>(
      "97927b83eb6b9fccda567f3bf12cbf49",
      data: {"roomId": roomId, "mickIndex": mickIndex, "mute": mute},
      fromJson: (json) => json as bool,
    );
    return result;
  }

  ///live/user/list
  @override
  Future<List<SocialChatUserProfile>> roomOnlineUsers(String roomId) async {
    final result = await http.get(
      "a01ade8fbb604c0904557a9483fcc4d9",
      queryParams: {"roomId": roomId},
      fromJson:
          (json) =>
              (json as List)
                  .map((e) => SocialChatUserProfile.fromJson(e))
                  .toList(),
    );
    return result;
  }

  ///user/user-profile/card
  @override
  Future<RoomUserCardRes> roomUserCard(String roomId, String userId) async {
    final result = await http.get<RoomUserCardRes>(
      "2fa1d4f56bb726558904ce2a50b83f967732a24a30dccae0c57cf03f27319ea4",
      queryParams: {"roomId": roomId, "userId": userId},
      fromJson: (json) => RoomUserCardRes.fromJson(json),
    );
    return result;
  }

  ///gift/list
  @override
  Future<List<SocialChatGiftRes>> giftList() async {
    final result = await http.get<List<SocialChatGiftRes>>(
      "3a613b7450f8fd9082b988bd21df454d",
      fromJson:
          (json) =>
              (json as List).map((e) => SocialChatGiftRes.fromJson(e)).toList(),
    );
    return result;
  }

  ///gift/group-tab
  @override
  Future<List<GiftByGroupRes>> giftListByGroup() async {
    final result = await http.get<List<GiftByGroupRes>>(
      "bfbb6d98524f1e8aecf695e32ed24c2f",
      fromJson:
          (json) =>
              (json as List).map((e) => GiftByGroupRes.fromJson(e)).toList(),
    );
    return result;
  }

  ///gift/batch
  @override
  Future<double> giveGift(
    List<String> acceptUserIds,
    String giftId,
    num quantity,
    bool checkCombo, {
    String? roomId,
    SCGiveAwayGiftRoomAcceptsCmd? accepts,
    String? dynamicContentId,
  }) async {
    Map<String, dynamic> params = {};
    if (roomId != null) {
      params["roomId"] = roomId;
    }
    params["giftId"] = giftId;
    params["acceptUserIds"] = acceptUserIds;
    params["quantity"] = quantity;
    params["checkCombo"] = checkCombo;
    if (accepts != null) {
      params["accepts"] = accepts.toJson();
    }
    if (dynamicContentId != null) {
      params["dynamicContentId"] = dynamicContentId;
    }

    final result = await http.post(
      "daa4f379ff3e429e55c318b6af7291e8",
      data: params,
      fromJson: (json) => json as double,
    );
    return result;
  }

  ///live/mic/kill
  @override
  Future<bool> micKill(String roomId, num mickIndex) async {
    final result = await http.post<bool>(
      "e50ed2f3406bc9421f3271f8be367d9b",
      data: {"roomId": roomId, "mickIndex": mickIndex},
      fromJson: (json) => json as bool,
    );
    return result;
  }

  ///sys/reported
  @override
  Future<bool> reported(
    String reportUserId,
    String reportedUserId,
    num reportType, {
    String? reportedContent,
    num? relatedId,
    String? imageUrls,
    String? videoUrls,
  }) async {
    Map<String, dynamic> params = {};
    params["reportUserId"] = reportUserId;
    params["reportedUserId"] = reportedUserId;
    params["reportType"] = reportType;
    if (reportedContent != null && reportedContent.isNotEmpty) {
      params["reportedContent"] = reportedContent;
    }
    if (relatedId != null) {
      params["relatedId"] = relatedId;
    }
    if (imageUrls != null && imageUrls.isNotEmpty) {
      params["imageUrls"] = imageUrls;
    }
    if (videoUrls != null && videoUrls.isNotEmpty) {
      params["videoUrls"] = videoUrls;
    }
    final result = await http.post(
      "552d752693c91a4a3dd9723634dff21f",
      data: params,
      fromJson: (json) => json as bool,
    );
    return result;
  }

  ///room/live-voice/search
  @override
  Future<List<SocialChatRoomRes>> searchRoom(String roomAccount) async {
    final result = await http.get<List<SocialChatRoomRes>>(
      "363603111e51beac2d183014dd29b81cce9dda0f9cd8c267f6e4fd3f05bda090",
      queryParams: {"roomAccount": roomAccount},
      fromJson:
          (json) =>
              (json as List).map((e) => SocialChatRoomRes.fromJson(e)).toList(),
    );
    return Future.wait(result.map(_hydrateRoomRes));
  }

  ///room/blacklist/join
  @override
  Future<SCRoomJoinBlackListRes> joinBlacklist(
    String roomId,
    String userId,
    num outTime,
  ) async {
    final result = await http.post<SCRoomJoinBlackListRes>(
      "fe07c4b4a0ab1a38a5674c77444296f1a31f65259a63574dbbfbfe543f1b99a6",
      data: {"roomId": roomId, "userId": userId, "outTime": outTime},
      fromJson: (json) => SCRoomJoinBlackListRes.fromJson(json),
    );
    return result;
  }

  ///room/blacklist/remove
  @override
  Future removeBlacklist(String roomId, String userId) async {
    final result = await http.post(
      "68900c787a89c1092b21ee1a610ef323380d4f62784dacdb4e3d4e1f60770a39",
      data: {"roomId": roomId, "userId": userId},
      fromJson: (json) => null,
    );
    return result;
  }

  ///user/count/guard
  @override
  Future<List<UserCountGuardRes>> userCountGuard(String userId) async {
    final result = await http.get<List<UserCountGuardRes>>(
      "cef5832baa42d4adb30f4b10bef0887e574aff257ce7e668d08f4caccd1c6232",
      queryParams: {"userId": userId},
      fromJson:
          (json) =>
              (json as List).map((e) => UserCountGuardRes.fromJson(e)).toList(),
    );
    return result;
  }

  ///material/emoji/all
  @override
  Future<List<SCRoomEmojiRes>> emojiAll() async {
    final result = await http.get<List<SCRoomEmojiRes>>(
      "1d2546ea50639e65f04d029dd0a9655eda4aeb3a4bd182b663d60d87cb3f2938",
      fromJson:
          (json) =>
              (json as List).map((e) => SCRoomEmojiRes.fromJson(e)).toList(),
    );
    return result;
  }

  ///room/member/change-role
  @override
  Future<bool> changeRoomRole(
    String roomId,
    String userType,
    String changeUserId,
    String operatorUserId,
    String reason,
  ) async {
    final result = await http.put<bool>(
      "39b2c4ffda0682c126435fc37480a0961be75ad669bd0bf28d4e875a45934dfe",
      data: {
        "roomId": roomId,
        "userType": userType,
        "changeUserId": changeUserId,
        "operatorUserId": operatorUserId,
        "reason": reason,
      },
      fromJson: (json) => json as bool,
    );
    return result;
  }

  ///room/setting/locked
  @override
  Future<bool> roomLocked(String roomId, String password) async {
    final result = await http.put<bool>(
      "e9531da4dd5c83bd5386366519ac6d0b727c997eb7a1adb8323f850b6c541f3b",
      data: {"roomId": roomId, "password": password},
      fromJson: (json) => json as bool,
    );
    return result;
  }

  ///room/setting/unlocked
  @override
  Future<bool> roomUnlocked(String roomId) async {
    final result = await http.post<bool>(
      "d8e78b8fb4cf9f0d41716d9978235334d9382f6a419ce06c2dab0b362c318a5d",
      data: {"roomId": roomId},
      fromJson: (json) => json as bool,
    );
    return result;
  }

  ///room/setting
  @override
  Future<bool> updateRoomSetting(
    String roomId,
    String roomAcount,
    BuildContext context, {
    bool? touristMike,
    String? takeMicRole,
    bool? touristMsg,
    String? joinGolds,
    num? mikeSize,
    bool? allowMusic,
    bool? adminLockSeat,
    bool? showHeartbeat,
    bool? openKtvMode,
    String? roomSpecialMikeType,
  }) async {
    Map<String, dynamic> params = {};
    params["roomId"] = roomId;
    if (touristMike != null) {
      params["touristMike"] = touristMike;
    }
    if (takeMicRole != null) {
      params["takeMicRole"] = takeMicRole;
    }
    if (touristMsg != null) {
      params["touristMsg"] = touristMsg;
    }
    if (joinGolds != null) {
      params["joinGolds"] = joinGolds;
    }
    if (mikeSize != null) {
      params["mikeSize"] = mikeSize;
    }
    if (allowMusic != null) {
      params["allowMusic"] = allowMusic;
    }
    if (adminLockSeat != null) {
      params["adminLockSeat"] = adminLockSeat;
    }
    if (showHeartbeat != null) {
      params["showHeartbeat"] = showHeartbeat;
    }
    if (openKtvMode != null) {
      params["openKtvMode"] = openKtvMode;
    }
    if (roomSpecialMikeType != null) {
      params["roomSpecialMikeType"] = roomSpecialMikeType;
    }
    final result = await http.put<bool>(
      "cd447427897a27ec5a710ae5861907c0",
      data: params,
      fromJson: (json) => json as bool,
    );

    Provider.of<RtmProvider>(context, listen: false).dispatchMessage(
      Msg(
        groupId: roomAcount,
        msg: roomId,
        type: SCRoomMsgType.roomSettingUpdate,
      ),
      addLocal: false,
    );
    return result;
  }

  ///room/member
  @override
  Future<List<SocialChatRoomMemberRes>> roomMember(
    String roomId, {
    String? lastId,
  }) async {
    Map<String, dynamic> parm = {};
    parm["roomId"] = roomId;
    if (lastId != null) {
      parm["lastId"] = lastId;
    }
    final result = await http.get<List<SocialChatRoomMemberRes>>(
      "76393fe91160b664a81fdc0545a586ef",
      queryParams: parm,
      fromJson:
          (json) =>
              (json as List)
                  .map((e) => SocialChatRoomMemberRes.fromJson(e))
                  .toList(),
    );
    return result;
  }

  ///room/contribution/rank
  @override
  Future<List<RoomGiftRankRes>> roomContributionRank(
    String roomId,
    String dataType, {
    num size = 10,
  }) async {
    Map<String, dynamic> parm = {};
    parm["roomId"] = roomId;
    parm["dataType"] = dataType;
    parm["size"] = size;
    final result = await http.get<List<RoomGiftRankRes>>(
      "730cfe8ab28a5bb6b75adb2d29320bd80ed2ff7efd67897d5b80fd620a1b0676",
      queryParams: parm,
      fromJson:
          (json) =>
              (json as List).map((e) => RoomGiftRankRes.fromJson(e)).toList(),
    );
    return result;
  }

  ///room/setting/kick-off-microphone
  @override
  Future<bool> kickOffMicrophone(String roomId, String kickUserId) async {
    final result = await http.post<bool>(
      "a4465894e21be08d833ef701566ffe1b6a835338046b35fb94271445c996f6e3574aff257ce7e668d08f4caccd1c6232",
      data: {"roomId": roomId, "kickUserId": kickUserId},
      fromJson: (json) => json as bool,
    );
    return result;
  }

  ///gift/give/lucky-gift
  @override
  Future<double> giveLuckyGift(
    List<String> acceptUserIds,
    String giftId,
    num quantity,
    bool checkCombo, {
    String? roomId,
    SCGiveAwayGiftRoomAcceptsCmd? accepts,
  }) async {
    Map<String, dynamic> params = {};
    if (roomId != null) {
      params["roomId"] = roomId;
    }
    params["giftId"] = giftId;
    params["acceptUserIds"] = acceptUserIds;
    params["quantity"] = quantity;
    params["checkCombo"] = checkCombo;
    if (accepts != null) {
      params["accepts"] = accepts.toJson();
    }

    final result = await http.post(
      "6ddf7ebecfa97adf23c6303877c7763ce591ff710a7abc4fe1e335d16efee21b",
      data: params,
      fromJson: (json) => json as double,
    );
    return result;
  }

  ///activity/leaderboard/appLeaderboard
  @override
  Future<SCBannerLeaderboardRes> appLeaderboard() async {
    final result = await http.get<SCBannerLeaderboardRes>(
      "04f600f838ff20e7f794d3b555103541adda7fb851a14e1c733d58bc5cd3a23b343860371cb9a34e6cdb9005c91c78a9",
      fromJson: (json) => SCBannerLeaderboardRes.fromJson(json),
    );
    return result;
  }

  ///gift/backpack
  @override
  Future<List<SocialChatGiftBackpackRes>> giftBackpack() async {
    final result = await http.get<List<SocialChatGiftBackpackRes>>(
      "48ab0afa0e4305070eaa82edc3fc3996",
      fromJson:
          (json) =>
              (json as List)
                  .map((e) => SocialChatGiftBackpackRes.fromJson(e))
                  .toList(),
    );
    return result;
  }

  ///api/rocket/status
  @override
  Future<SCRoomRocketStatusRes> rocketStatus(String roomId) async {
    Map<String, dynamic> params = {};
    params["roomId"] = roomId;
    final result = await http.get<SCRoomRocketStatusRes>(
      "1b650f6fc863c8c86ec8d921340a65ccba2fafbaede21817c8d7e89774331852",
      queryParams: params,
      fromJson: (json) => SCRoomRocketStatusRes.fromJson(json),
    );
    return result;
  }

  ///api/rocket/config/enabled
  @override
  Future<List<SCRoomRocketConfigRes>> rocketConfigEnabled() async {
    final result = await http.get<List<SCRoomRocketConfigRes>>(
      "09620f7f773a75af633e034b80393e0ee8adb46dafdd3600f74d3c85e2c07e4f",
      fromJson:
          (json) =>
              (json as List)
                  .map((e) => SCRoomRocketConfigRes.fromJson(e))
                  .toList(),
    );
    return result;
  }

  ///api/rocket/claim
  @override
  Future<bool> rocketClaim(String roomId) async {
    final result = await http.post<bool>(
      "4c083b13f2be2a26641018619bdc0347574aff257ce7e668d08f4caccd1c6232",
      data: {"roomId": roomId},
      fromJson: (json) => json as bool,
    );
    return result;
  }

  ///room-violation/handle
  @override
  Future<SCViolationHandleRes> roomViolationHandle(
    String roomId,
    int violationType,
    int operationType,
    String description, {
    List<String>? imageUrls,
  }) async {
    Map<String, dynamic> parm = {};
    parm["roomId"] = roomId;
    parm["violationType"] = violationType;
    parm["operationType"] = operationType;
    parm["description"] = description;
    if (imageUrls != null && imageUrls.isNotEmpty) {
      parm["screenshotUrls"] = imageUrls;
    }
    final result = await http.post<SCViolationHandleRes>(
      "fc47c4e6e3ba228391cd35bf99f301206f894acdcdbac7ccb7e88e9d69ee3eff",
      data: parm,
      fromJson: (json) => SCViolationHandleRes.fromJson(json),
    );
    return result;
  }

  ///room/red-packet/list
  @override
  Future<List<SCRoomRedPacketListRes>> roomRedPacketList(
    String roomId,
    int current, {
    int size = 20,
  }) async {
    Map<String, dynamic> parm = {};
    parm["roomId"] = roomId;
    parm["current"] = current;
    parm["size"] = size;
    final result = await http.get<List<SCRoomRedPacketListRes>>(
      "318de84592dca60c287ba2f54d60756abc4a9e8c4704c0f73c085e7ab50e7fdb",
      queryParams: parm,
      fromJson:
          (json) =>
              (json as List)
                  .map((e) => SCRoomRedPacketListRes.fromJson(e))
                  .toList(),
    );
    return result;
  }

  ///room/red-packet/create
  @override
  Future<SCRoomRedPacketListRes> roomSendRedPacket(
    String roomId,
    String totalAmount,
    String totalCount,
    String expireMinutes,
  ) async {
    Map<String, dynamic> parm = {};
    parm["roomId"] = roomId;
    parm["totalAmount"] = totalAmount;
    parm["totalCount"] = totalCount;
    parm["expireMinutes"] = expireMinutes;
    final result = await http.post<SCRoomRedPacketListRes>(
      "318de84592dca60c287ba2f54d60756af01ca103e12cc332b59b5a8e39c778ec",
      data: parm,
      fromJson: (json) => SCRoomRedPacketListRes.fromJson(json),
    );
    return result;
  }

  ///room/red-packet/grab
  @override
  Future<SCRoomRedPacketGrabRes> roomRedPacketGrab(String packetId) async {
    Map<String, dynamic> parm = {};
    parm["packetId"] = packetId;
    final result = await http.post<SCRoomRedPacketGrabRes>(
      "318de84592dca60c287ba2f54d60756a0b2a61d0ce4f3f4d50875dcc95b640af",
      data: parm,
      fromJson: (json) => SCRoomRedPacketGrabRes.fromJson(json),
    );
    return result;
  }

  ///room/red-packet/detail
  @override
  Future<SCRoomRedPacketDetailRes> roomRedPacketDetail(String packetId) async {
    Map<String, dynamic> parm = {};
    parm["packetId"] = packetId;
    final result = await http.get<SCRoomRedPacketDetailRes>(
      "318de84592dca60c287ba2f54d60756a7f342deecb1b83d2d8429c59146f10f0",
      queryParams: parm,
      fromJson: (json) => SCRoomRedPacketDetailRes.fromJson(json),
    );
    return result;
  }

  ///activity/room-contribution-activity/room-reward/info
  @override
  Future<SCRoomRewardInfoRes> roomRewardInfo(String roomId) async {
    Map<String, dynamic> parm = {};
    parm["roomId"] = roomId;
    final result = await http.get<SCRoomRewardInfoRes>(
      "fe8a114454bb0a64c51b5a2840b89b9caad8e1b76b3e1c570f21d856505cee7ddf616bd4bdc133af05422ff3f7becc575ad9f024e25ab8275b5792a94159a781",
      queryParams: parm,
      fromJson: (json) => SCRoomRewardInfoRes.fromJson(json),
    );
    return result;
  }

  ///activity/room-contribution-activity/room-reward/receive
  @override
  Future<bool> roomRewardReceive(String roomId) async {
    Map<String, dynamic> parm = {};
    parm["roomId"] = roomId;
    final result = await http.post<bool>(
      "1224764475bbd027233e79b81fbdbbf8b25565bc1234221b5e7f9651e0d97576fbcc314a4dd141539dc44cd84f2f13e4c35b35e57872c47078faccd94224944e",
      data: parm,
      fromJson: (json) => json as bool,
    );
    return result;
  }

  ///room/red-packet/create-platform
  @override
  Future<SCRoomRedPacketListRes> sendPlatformRedPack(
    String roomId,
    String totalAmount,
    String totalCount,
    String expireMinutes,
  ) async {
    Map<String, dynamic> parm = {};
    parm["roomId"] = roomId;
    parm["totalAmount"] = totalAmount;
    parm["totalCount"] = totalCount;
    parm["expireMinutes"] = expireMinutes;
    final result = await http.post<SCRoomRedPacketListRes>(
      "318de84592dca60c287ba2f54d60756a3d2cb7989afc93dcdbec1a68c53cac37",
      data: parm,
      fromJson: (json) => SCRoomRedPacketListRes.fromJson(json),
    );
    return result;
  }

  ///gift/activity/list
  @override
  Future<List<SocialChatGiftRes>> giftActivityList() async {
    final result = await http.get<List<SocialChatGiftRes>>(
      "60296415428765e04263c733bfc8428c397bb180e31856d94bf25d85eb342787",
      fromJson:
          (json) =>
              (json as List).map((e) => SocialChatGiftRes.fromJson(e)).toList(),
    );
    return result;
  }

  ///room-task/list
  @override
  Future<SCRoomTaskListRes> roomTaskList(int taskCategory) async {
    Map<String, dynamic> parm = {};
    parm["taskCategory"] = taskCategory;
    final result = await http.get<SCRoomTaskListRes>(
      "30743db31a4b5236451c71864f914359",
      queryParams: parm,
      fromJson: (json) => SCRoomTaskListRes.fromJson(json),
    );
    return result;
  }

  ///room-task/claim
  @override
  Future<Tiers> roomTaskClaim(String taskCode) async {
    Map<String, dynamic> parm = {};
    parm["taskCode"] = taskCode;
    final result = await http.post<Tiers>(
      "439c60bae741f83884ada20b837a00f9",
      data: parm,
      fromJson: (json) => Tiers.fromJson(json),
    );
    return result;
  }

  ///room-task/claimable-count
  @override
  Future<SCRoomTaskClaimableCountRes> roomTaskClaimableCount() async {
    final result = await http.get<SCRoomTaskClaimableCountRes>(
      "dba51232871855314973867d38c76191ae96d33f4d1b3265974cd070f03c3830",
      fromJson: (json) => SCRoomTaskClaimableCountRes.fromJson(json),
    );
    return result;
  }
}
