import 'package:flutter_map/flutter_map.dart';
import 'package:location/data/bean/user_info.dart';
import 'package:location/data/consts/constants.dart';

class Location2MarkerUtil {
  Location2MarkerUtil._();

  static Marker userInfo2Marker(UserInfo e, bool isSelected, int? electric) {
    final marker = Marker(
      id: e.id,
      markerName: e.getUserNickName(),
      longitude: e.lastLocation.value?.longitude,
      latitude: e.lastLocation.value?.latitude,
      markerType: e.id == Constants.mineLocationId
          ? MarkerType.mine
          : MarkerType.friend,
      isSelected: isSelected,
      customAvatarUrl: e.avatar,
    );
    if (electric != null) {
      marker.tags = {'electric': electric};
    }
    return marker;
  }

  static List<Marker> userInfoList2MarkerList(List<UserInfo> list,
      bool isMemberExpired, UserInfo? selectedFriend,
      {int? electric}) {
    List<Marker> markers = [];
    for (var e in list) {
      if (e.isMine == true) {
        markers.add(userInfo2Marker(e, e.id == selectedFriend?.id, electric));
      } else if (e.blockedMe != true &&
          e.lastLocation.value?.longitude != null &&
          e.lastLocation.value?.latitude != null &&
          !isMemberExpired) {
        markers.add(userInfo2Marker(e, e.id == selectedFriend?.id, electric));
      }
    }
    return markers;
  }
}
