import { Building } from "./building/building";
import { LumberHut } from "./building/lumber-building";
import { ResouceBuilding } from "./building/resource-building";

export class BuildingRenderer {
  private scene: Phaser.Scene;
  private sprites = new Map<Building, Phaser.GameObjects.Image>();

  constructor(scene: Phaser.Scene) {
    this.scene = scene;
  }

  /** Wird aufgerufen, wenn ein neues Gebäude entsteht */
  addBuilding(building: Building) {
    let textureKey = 'default';
    switch (building.constructor) {
      case LumberHut:
        textureKey = 'lumberhut';
        break;
      case Storage:
        textureKey = 'storage';
        break;
      default:
        textureKey = 'default';
    }

    const sprite = this.scene.add.image(
      building.x * 32 + 16, // tileSize=32
      building.y * 32 + 16,
      textureKey
    );
    sprite.setOrigin(0.5);
    sprite.setDepth(5);
    this.sprites.set(building, sprite);
  }

  /** Wird jedes Frame aufgerufen */
  update() {
    // Hier kannst du Animation, Statusfarben, etc. updaten
    for (const [b, s] of this.sprites) {
      // z.B. "aktiv" Gebäude leicht heller rendern
      if (b instanceof ResouceBuilding && b.assignedWorker != null) {
        s.setTint(0xffffff);
      } else {
        s.setTint(0xaaaaaa);
      }
    }
  }
}