import 'package:wisata_app/models/destination.dart';

import '../../../../services/destination_service.dart';
import '../../domain/entities/ar_experience.dart';
import '../../domain/repositories/ar_experience_repository.dart';

class DestinationArExperienceRepository implements ArExperienceRepository {
  const DestinationArExperienceRepository({
    this.destinationService = const DestinationService(),
  });

  final DestinationService destinationService;

  @override
  Future<ArExperience> getExperienceByDestinationId(
      String destinationId) async {
    final destination =
        await destinationService.getDestinationDetail(destinationId);
    if (destination == null) {
      throw StateError('Destinasi dengan ID $destinationId tidak ditemukan.');
    }
    return fromDestination(destination);
  }

  ArExperience fromDestination(Destination destination) {
    if (destination.modelPath.isEmpty) {
      throw StateError('${destination.title} belum memiliki model AR.');
    }

    return ArExperience(
      destinationId: destination.id,
      destinationTitle: destination.title,
      modelPath: destination.modelPath,
      description: destination.arDescription,
    );
  }
}
