import 'package:firebase_data_connect/firebase_data_connect.dart';
import 'package:krow_data_connect/krow_data_connect.dart';
import 'package:krow_domain/krow_domain.dart';

import '../../domain/repositories/attire_repository.dart';

/// Implementation of [AttireRepository].
///
/// Delegates data access to [DataConnectService].
class AttireRepositoryImpl implements AttireRepository {
  /// The Data Connect service.
  final DataConnectService _service;

  /// Creates an [AttireRepositoryImpl].
  AttireRepositoryImpl({DataConnectService? service})
      : _service = service ?? DataConnectService.instance;

  @override
  Future<List<AttireItem>> getAttireOptions() async {
    return _service.run(() async {
      final QueryResult<ListAttireOptionsData, void> result =
          await _service.connector.listAttireOptions().execute();
      return result.data.attireOptions
          .map((ListAttireOptionsAttireOptions e) => AttireItem(
                id: e.itemId,
                label: e.label,
                iconName: e.icon,
                imageUrl: e.imageUrl,
                isMandatory: e.isMandatory ?? false,
              ))
          .toList();
    });
  }

  @override
  Future<void> saveAttire({
    required List<String> selectedItemIds,
    required Map<String, String> photoUrls,
  }) async {
    // TODO: Connect to actual backend mutation when available.
    // For now, simulate network delay as per prototype behavior.
    await Future<void>.delayed(const Duration(seconds: 1));
  }

  @override
  Future<String> uploadPhoto(String itemId) async {
    // TODO: Connect to actual storage service/mutation when available.
    // For now, simulate upload delay and return mock URL.
    await Future<void>.delayed(const Duration(seconds: 1));
    return 'mock_url_for_$itemId';
  }
}
