import '../consts/marker_type.dart';
import "codable.dart";

class Marker implements Codable {
  String id;

  String markerName;

  double? longitude;

  double? latitude;

  MarkerType markerType;

  bool isSelected;

  String? customAvatarUrl;

  dynamic tags;

  Marker({
    required this.id,
    required this.markerName,
    required this.longitude,
    required this.latitude,
    required this.markerType,
    this.isSelected = false,
    this.customAvatarUrl,
    this.tags,
  });

  @override
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'markerName': markerName,
      'longitude': longitude,
      'latitude': latitude,
      'markerType': markerType.value,
      'isSelected': isSelected,
      'customAvatarUrl': customAvatarUrl,
      'tags': tags,
    };
  }

  factory Marker.fromJson(Map<String, dynamic> map) {
    return Marker(
      id: map['id'],
      markerName: map['markerName'],
      longitude: map['longitude'],
      latitude: map['latitude'],
      markerType: MarkerType.fromValue(map['markerType'] as int),
      isSelected: map['isSelected'],
      customAvatarUrl: map['customAvatarUrl'] as String?,
      tags: map['tags'] ? map['tags'] : null,
    );
  }
}
