/// Design Request Repository Implementation
///
/// Implements the design request repository interface.
library;

import 'package:worker/features/showrooms/data/datasources/design_request_remote_datasource.dart';
import 'package:worker/features/showrooms/domain/entities/design_request.dart';
import 'package:worker/features/showrooms/domain/repositories/design_request_repository.dart';

/// Design Request Repository Implementation
class DesignRequestRepositoryImpl implements DesignRequestRepository {
  const DesignRequestRepositoryImpl(this._remoteDataSource);

  final DesignRequestRemoteDataSource _remoteDataSource;

  @override
  Future<List<DesignRequest>> getDesignRequests({
    int limitStart = 0,
    int limitPageLength = 0,
  }) async {
    try {
      final models = await _remoteDataSource.getDesignRequests(
        limitStart: limitStart,
        limitPageLength: limitPageLength,
      );
      return models.map((model) => model.toEntity()).toList();
    } catch (e) {
      rethrow;
    }
  }

  @override
  Future<DesignRequest> getDesignRequestDetail(String name) async {
    try {
      final model = await _remoteDataSource.getDesignRequestDetail(name);
      return model.toEntity();
    } catch (e) {
      rethrow;
    }
  }

  @override
  Future<String> createDesignRequest({
    required String subject,
    required String area,
    required String region,
    required String desiredStyle,
    String? estimatedBudget,
    required String detailedRequirements,
    required String dateline,
  }) async {
    try {
      return await _remoteDataSource.createDesignRequest(
        subject: subject,
        area: area,
        region: region,
        desiredStyle: desiredStyle,
        estimatedBudget: estimatedBudget,
        detailedRequirements: detailedRequirements,
        dateline: dateline,
      );
    } catch (e) {
      rethrow;
    }
  }

  @override
  Future<void> uploadDesignRequestFile({
    required String requestId,
    required String filePath,
    required String fileName,
  }) async {
    try {
      await _remoteDataSource.uploadDesignRequestFile(
        requestId: requestId,
        filePath: filePath,
        fileName: fileName,
      );
    } catch (e) {
      rethrow;
    }
  }
}
