import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AtmospherePreviewService, PreviewGenerationResult } from '../services/atmosphere-preview.service';
import { SceneGenerationService } from '../services/scene-generation.service';
import { SceneTemplate, SceneParams } from '../models/requirement-mapping.interface';
import { Observable } from 'rxjs';

@Component({
  selector: 'app-test-atmosphere-preview',
  standalone: true,
  imports: [CommonModule],
  templateUrl: './test-atmosphere-preview.html',
  styleUrls: ['./test-atmosphere-preview.scss']
})
export class TestAtmospherePreviewComponent implements OnInit {
  
  previewResult: PreviewGenerationResult | null = null;
  isGenerating = false;
  error: string | null = null;
  
  // 测试场景类型
  testSceneTypes = [
    SceneTemplate.LIVING_ROOM_MODERN,
    SceneTemplate.BEDROOM_COZY,
    SceneTemplate.KITCHEN_CONTEMPORARY
  ];
  
  selectedSceneType = SceneTemplate.LIVING_ROOM_MODERN;

  constructor(
    private atmospherePreviewService: AtmospherePreviewService,
    private sceneGenerationService: SceneGenerationService
  ) {}

  ngOnInit(): void {
    this.generateTestPreview();
  }

  generateTestPreview(): void {
    this.isGenerating = true;
    this.error = null;
    
    // 获取场景模板参数
    const sceneParams = this.sceneGenerationService.getSceneTemplate(this.selectedSceneType);
    
    // 生成氛围感预览图
    this.atmospherePreviewService.generateAtmospherePreview(
      sceneParams, 
      this.selectedSceneType,
      { quality: 'medium', style: 'realistic' }
    ).subscribe({
      next: (result) => {
        this.previewResult = result;
        this.isGenerating = false;
        console.log('氛围感预览图生成成功:', result);
      },
      error: (err) => {
        this.error = '生成预览图时发生错误: ' + err.message;
        this.isGenerating = false;
        console.error('氛围感预览图生成失败:', err);
      }
    });
  }

  onSceneTypeChange(value: string): void {
    this.selectedSceneType = value as SceneTemplate;
    this.generateTestPreview();
  }

  getSceneTypeName(sceneType: SceneTemplate): string {
    const names: Record<SceneTemplate, string> = {
      [SceneTemplate.LIVING_ROOM_MODERN]: '现代客厅',
      [SceneTemplate.LIVING_ROOM_CLASSIC]: '经典客厅',
      [SceneTemplate.BEDROOM_COZY]: '温馨卧室',
      [SceneTemplate.BEDROOM_MINIMAL]: '简约卧室',
      [SceneTemplate.KITCHEN_CONTEMPORARY]: '现代厨房',
      [SceneTemplate.KITCHEN_TRADITIONAL]: '传统厨房',
      [SceneTemplate.BATHROOM_LUXURY]: '豪华浴室',
      [SceneTemplate.BATHROOM_MINIMAL]: '简约浴室',
      [SceneTemplate.OFFICE_MODERN]: '现代办公室',
      [SceneTemplate.OFFICE_TRADITIONAL]: '传统办公室',
      [SceneTemplate.DINING_FORMAL]: '正式餐厅',
      [SceneTemplate.DINING_CASUAL]: '休闲餐厅',
      [SceneTemplate.STUDIO_APARTMENT]: '工作室公寓',
      [SceneTemplate.OUTDOOR_PATIO]: '户外露台',
      [SceneTemplate.OUTDOOR_GARDEN]: '户外花园'
    };
    return names[sceneType] || sceneType.toString();
  }
}
