import 'package:flutter/material.dart';
import 'package:maplibre_gl/maplibre_gl.dart';
import 'entity.dart';

/// 组件基类 - 代表实体的属性
abstract class Component {
  final String id;
  Entity? entity;

  Component({String? id}) : id = id ?? "${DateTime.now().millisecondsSinceEpoch}";
}

/// 标绘组件 - 用于在地图上绘制图形
class PlotComponent extends Component {
  final String plotType;
  final List<LatLng> coordinates;
  final Color color;
  final double strokeWidth;

  PlotComponent({
    super.id,
    required this.plotType,
    required this.coordinates,
    this.color = Colors.red,
    this.strokeWidth = 2.0,
  });
}

/// 图标组件 - 用于在地图上显示图标
class IconComponent extends Component {
  final String iconPath;
  LatLng position;
  final double size;

  IconComponent({
    super.id,
    required this.iconPath,
    required this.position,
    this.size = 30.0,
  });
}

/// 拖尾组件 - 用于显示移动实体的轨迹
class TrailComponent extends Component {
  final List<LatLng> trailPoints;
  final Color trailColor;
  final double maxLength;

  TrailComponent({
    super.id,
    List<LatLng>? trailPoints,
    this.trailColor = Colors.blue,
    this.maxLength = 20.0,
  }) : trailPoints = trailPoints ?? [];

  void addPoint(LatLng point) {
    trailPoints.add(point);
    if (trailPoints.length > maxLength) {
      trailPoints.removeAt(0);
    }
  }
}

/// 音频组件 - 用于播放与实体相关的音频
class AudioComponent extends Component {
  final String audioPath;
  final bool loop;
  final double volume;

  AudioComponent({
    super.id,
    required this.audioPath,
    this.loop = false,
    this.volume = 1.0,
  });
}

/// 移动组件 - 用于控制实体的移动
class MovementComponent extends Component {
  LatLng position;
  LatLng? target;
  double speed;

  MovementComponent({
    super.id,
    required this.position,
    this.target,
    this.speed = 1.0,
  });
}