import 'package:yumi/shared/business_logic/models/res/sc_google_pay_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_product_config_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_version_manage_latest_res.dart';
import 'package:yumi/shared/business_logic/models/res/country_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_index_banner_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_level_config_res.dart';
import 'package:yumi/shared/business_logic/models/res/login_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_start_page_res.dart';
import 'package:yumi/shared/business_logic/models/res/sc_top_four_with_reward_res.dart';
import 'package:yumi/shared/business_logic/models/res/version_manage_lates_review_res.dart';
import 'package:yumi/shared/business_logic/repositories/config_repository.dart';
import 'package:yumi/shared/data_sources/sources/remote/net/network_client.dart';

class SCConfigRepositoryImp implements SocialChatConfigRepository {
  static SCConfigRepositoryImp? _instance;

  SCConfigRepositoryImp._internal();

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

  ///sys/config/country
  @override
  Future<CountryRes> loadCountry() async {
    final result = await http.get(
      "9c370c6fef50fc728152e7a3fd5b47d2841a1d9a5a2b0bb769039fdd47f01585",
      fromJson: (json) => CountryRes.fromJson(json),
    );
    return result;
  }

  ///sys/config/banner
  @override
  Future<List<SCIndexBannerRes>> getBanner({List<String>?types}) async {
    Map<String, dynamic> params = {};
    if (types != null) {
      params["types"] = types;
    }
    final result = await http.get(
      "0d8319c7a696c73d58f5e0ae304dc663f574ade4154ed90ccaee524f6ba14490",
      queryParams: params,
      fromJson:
          (json) =>
              (json as List).map((e) => SCIndexBannerRes.fromJson(e)).toList(),
    );
    return result;
  }

  ///sys/config/enum/config
  @override
  Future<CountryRes> getConfig() async {
    final result = await http.get(
      "e6fcae3c4a41806e15b4fc015126361267972b2854bbea42d0f0089c5f1c7724",
      fromJson: (json) => CountryRes.fromJson(json),
    );
    return result;
  }

  ///sys/config/customer-service
  @override
  Future<CountryRes> getCustomerService() async {
    final result = await http.get(
      "ba316258c14cc3ebddb6d28ec314bc5704e593861ca693058e9e98ab3114cf05",
      fromJson: (json) => CountryRes.fromJson(json),
    );
    return result;
  }



  ///ranking/top-four-with-reward
  @override
  Future<List<SCTopFourWithRewardRes>> topFourWithReward() async {
    final result = await http.post<List<SCTopFourWithRewardRes>>(
      "162c2587d0236c6122a197f872daf865c29cc45b9c80570e9f4432051b2040e4",
      data: {},
      fromJson:
          (json) =>
              (json as List)
                  .map((e) => SCTopFourWithRewardRes.fromJson(e))
                  .toList(),
    );
    return result;
  }

  ///sys/config/sys/notice-message
  @override
  Future<CountryRes> getNoticeMessage() async {
    final result = await http.get(
      "b45ab3738ec718525eb02dcc8b1c79165ae6295dd8ec0e521307c70a005119b2",
      fromJson: (json) => CountryRes.fromJson(json),
    );
    return result;
  }


  ///sys/config/banner/start-page
  @override
  Future<List<SCStartPageRes>> getStartPage() async {
    final result = await http.get(
      "0d8319c7a696c73d58f5e0ae304dc66352cfd4d4480504cd5f589338f4f90157",
      fromJson:
          (json) =>
              (json as List).map((e) => SCStartPageRes.fromJson(e)).toList(),
    );
    return result;
  }

  ///sys/config/room/getSudCode
  @override
  Future<CountryRes> getSudCode() async {
    final result = await http.get(
      "690f390b1c91b6cb0b4fdbeb98215a9f2fb1663213697d032f7fe4dd9aa9e8f4",
      fromJson: (json) => CountryRes.fromJson(json),
    );
    return result;
  }

  ///sys/config/country/top-six
  @override
  Future<CountryRes> loadTopSix() async {
    final result = await http.get(
      "9c370c6fef50fc728152e7a3fd5b47d263ca03b0e63d90aeb3c57f8d946ecd78",
      fromJson: (json) => CountryRes.fromJson(json),
    );
    return result;
  }

  ///order/product-config
  @override
  Future<List<SCProductConfigRes>> productConfig() async {
    final result = await http.get<List<SCProductConfigRes>>(
      "1585c72b88d0d249c7078aae852a0806cc3d8e483b8d861962a977a00523180a",
      fromJson:
          (json) =>
              (json as List).map((e) => SCProductConfigRes.fromJson(e)).toList(),
    );
    return result;
  }

  ///order/purchase-pay/google
  @override
  Future<SCGooglePayRes> googlePay(
    String product,
    String signature,
    String purchaseData, {
    String? friendId,
  }) async {
    Map<String, dynamic> params = {};
    params["product"] = product;
    params["signature"] = signature;
    params["purchaseData"] = purchaseData;
    if (friendId != null) {
      params["friendId"] = friendId;
    }
    final result = await http.post<SCGooglePayRes>(
      "3a5ab504e90faccde8258f4ea1dd6bcdad6eec89ad8cc807b184537e0fdb6904",
      data: params,
      fromJson: (json) => SCGooglePayRes.fromJson(json),
    );
    return result;
  }

  ///order/purchase-pay/apple
  @override
  Future<SCGooglePayRes> applePay(
    String product,
    String receipt,
    String transaction, {
    String? friendId,
  }) async {
    Map<String, dynamic> params = {};
    params["product"] = product;
    params["receipt"] = receipt;
    params["transaction"] = transaction;
    if (friendId != null) {
      params["friendId"] = friendId;
    }
    final result = await http.post<SCGooglePayRes>(
      "3a5ab504e90faccde8258f4ea1dd6bcd7e041553c5af750a6eff64c18e7de276",
      data: params,
      fromJson: (json) => SCGooglePayRes.fromJson(json),
    );
    return result;
  }

  ///sys/static-config/level
  @override
  Future<SCLevelConfigRes> configLevel() async {
    final result = await http.get(
      "9d964981940fe0403d53d6f44e7cf7a48c2534f1e31f6b5fa9b1fae672b836d1",
      fromJson: (json) => SCLevelConfigRes.fromJson(json),
    );
    return result;
  }


  ///sys/version/manage/release/latest
  @override
  Future<SCVersionManageLatestRes> versionManageLatest() async{
    final result = await http.get<SCVersionManageLatestRes>(
      "ee9584f714ded864780e47dab2cf4a2e84ac21c90fcd0966a13d2ce9e8845eb8e580afbe66f9f0fef79429cd5c1e0687",
      fromJson: (json) => SCVersionManageLatestRes.fromJson(json),
    );
    return result;
  }

  ///sys/version/manage/latest/review
  @override
  Future<VersionManageLatesReviewRes> versionManageLatestReview() async{
    final result = await http.get<VersionManageLatesReviewRes>(
      "ee9584f714ded864780e47dab2cf4a2e11ce42bdd061186d4efe3305b73f10fe574aff257ce7e668d08f4caccd1c6232",
      fromJson: (json) => VersionManageLatesReviewRes.fromJson(json),
    );
    return result;
  }

  ///sys/config/customer-service
  @override
  Future<SocialChatUserProfile> customerService() async{
    final result = await http.get<SocialChatUserProfile>(
      "ba316258c14cc3ebddb6d28ec314bc5704e593861ca693058e9e98ab3114cf05",
      fromJson: (json) => SocialChatUserProfile.fromJson(json),
    );
    return result;
  }

}
