import 'package:flame/components.dart';
import 'package:flutter/material.dart';
import 'package:shitman/game/components/base.dart';

/// Base class for all level building block components
abstract class LevelComponent extends DecorativeShit with Stationary {
  Vector2 gridPosition;
  
  LevelComponent({required this.gridPosition}) {
    size = Vector2.all(80.0);
  }

  /// Convert grid position to world position
  Vector2 getWorldPosition(double cellSize) {
    return Vector2(gridPosition.x * cellSize, gridPosition.y * cellSize);
  }
}

/// Base class for road components
abstract class RoadComponent extends LevelComponent {
  static const double roadWidth = 60.0;
  
  RoadComponent({required super.gridPosition});

  @override
  void render(Canvas canvas) {
    final roadPaint = Paint()..color = const Color(0xFF333333);
    canvas.drawRect(size.toRect(), roadPaint);
    
    // Draw road markings
    final markingPaint = Paint()
      ..color = const Color(0xFFFFFFFF)
      ..strokeWidth = 2.0;
    
    renderRoadMarkings(canvas, markingPaint);
  }
  
  /// Override in subclasses to render specific road markings
  void renderRoadMarkings(Canvas canvas, Paint paint);
  
  @override
  Future<void> reset() async {
    // Default implementation for road components
  }
}

/// Base class for structure components (houses, etc.)
abstract class StructureComponent extends LevelComponent {
  StructureComponent({required super.gridPosition});
  
  @override
  Future<void> reset() async {
    // Default implementation for structure components
  }
}

/// Base class for security components
abstract class SecurityComponent extends InteractiveShit {
  double detectionRange;
  bool isActive;
  
  SecurityComponent({
    required Vector2 position,
    required this.detectionRange,
    this.isActive = true,
  }) {
    this.position = position;
  }
  
  /// Check if player is detected by this security component
  bool detectsPlayer(Vector2 playerPosition, double playerStealthLevel);
  
  /// Get the detection radius considering stealth
  double getEffectiveDetectionRange(double playerStealthLevel) {
    return detectionRange * (1.0 - playerStealthLevel);
  }
}