import 'dart:async';

import 'config/location_option.dart';
import 'models/wayz_geocode_response.dart';
import 'models/wayz_reverse_geocode_response.dart';
import 'wz_location_plugin_platform_interface.dart';

export 'wz_location_plugin_stream.dart';

class WzLocationPlugin {
  Future<String?> getPlatformVersion() {
    return WzLocationPluginPlatform.instance.getPlatformVersion();
  }

  Future<void> setApiKey(String apiKey) {
    return WzLocationPluginPlatform.instance.setApiKey(apiKey);
  }

  static Future<void> updatePrivacyShow(bool hasContains, bool hasShow) {
    return WzLocationPluginPlatform.instance.updatePrivacyShow(hasContains, hasShow);
  }

  static Future<void> updatePrivacyAgree(bool hasAgree) {
    return WzLocationPluginPlatform.instance.updatePrivacyAgree(hasAgree);
  }

  /// 设置定位参数
  Future<void> setLocationOption(WzLocationOption locationOption) {
    return WzLocationPluginPlatform.instance.setLocationOption(locationOption);
  }

  ///开始定位
  Future<void> startLocation() {
    return WzLocationPluginPlatform.instance.startLocation();
  }

  ///停止定位
  Future<void> stopLocation() {
    return WzLocationPluginPlatform.instance.stopLocation();
  }

  /// 当位子发生改变（与 [wzLocationPluginStream] 相同数据源）。
  Stream<Map<String, Object?>> onLocationChanged() {
    return WzLocationPluginPlatform.instance.locationStream;
  }

  /// 正地理编码
  Future<WzGeocodeResponse> geocode({
    required String address,
    String? city,
  }) {
    return WzLocationPluginPlatform.instance.geocode(address: address, city: city);
  }

  /// 逆地理编码
  Future<WzReverseGeocodeResponse> reverseGeocode(
      {required String asset,
      required double longitude,
      required double latitude,
      String? responseSprf,
      String? locationSpatialReference,
      String? source,
      double? accuracy}) {
    return WzLocationPluginPlatform.instance.reverseGeocode(
      asset: asset,
      longitude: longitude,
      latitude: latitude,
      responseSprf: responseSprf,
      spatialReference: locationSpatialReference,
      source: source,
      accuracy: accuracy,
    );
  }

  /// POI 关键字搜索
  Future<List<WzGeocodeResponse>> searchPoiByKeyword({
    required String name,
    String? city,
    String? cityCode,
    int pageIndex = 1,
    int pageSize = 20,
  }) {
    return WzLocationPluginPlatform.instance.searchPoiByKeyword(
        name: name, city: city, cityCode: cityCode, pageIndex: pageIndex, pageSize: pageSize);
  }

  /// POI 周边搜索
  Future<List<WzGeocodeResponse>> searchPoiNearby({
    required double longitude,
    required double latitude,
    required int radiusMeters,
    String? keywords,
    String? category,
    String? orderBy,
    int pageIndex = 1,
    int pageSize = 20,
  }) {
    return WzLocationPluginPlatform.instance.searchPoiNearby(
        location: '$longitude,$latitude',
        radiusMeters: radiusMeters,
        keywords: keywords,
        category: category,
        orderBy: orderBy,
        pageIndex: pageIndex,
        pageSize: pageSize);
  }
}
