import '../../domain/entities/task.dart';
import '../../domain/repositories/tasks_repository.dart';
import '../datasources/tasks_datasource.dart';

class TasksRepositoryImpl implements TasksRepository {
  final TasksDatasource _datasource;

  TasksRepositoryImpl(this._datasource);

  @override
  Future<List<Task>> getTasks({String? status}) async {
    final models = await _datasource.fetchTasks(status: status);
    return models.map((m) => m.toEntity()).toList();
  }

  @override
  Future<Task> getTaskById(String id) async {
    final model = await _datasource.fetchTaskById(id);
    return model.toEntity();
  }

  @override
  Future<Task> createTask({
    required String title,
    String? description,
    String? priority,
    String? serverId,
  }) async {
    final model = await _datasource.createTask(
      title: title,
      description: description,
      priority: priority,
      serverId: serverId,
    );
    return model.toEntity();
  }

  @override
  Future<Task> updateTask(String id, Map<String, dynamic> updates) async {
    final model = await _datasource.updateTask(id, updates);
    return model.toEntity();
  }

  @override
  Future<void> deleteTask(String id) async {
    await _datasource.deleteTask(id);
  }
}
