import 'package:dio/dio.dart';
import '../../domain/repositories/kb_repository.dart';
import '../datasources/kb_remote_datasource.dart';

class KBRepositoryImpl implements KBRepository {
  final KBRemoteDatasource remote;

  KBRepositoryImpl(this.remote);

  @override
  Future<List<String>> getKnowledgeBases() async {
    try {
      return await remote.getKnowledgeBases();
    } on DioException catch (e) {
      throw e.error ?? e;
    }
  }

  @override
  Future<String> uploadToKB({
    required String kbName,
    List<String>? urls,
    List<String>? fileNames,
    List<List<int>>? fileBytes,
  }) async {
    try {
      return await remote.uploadToKB(
        kbName: kbName,
        urls: urls,
        fileNames: fileNames,
        fileBytes: fileBytes,
      );
    } on DioException catch (e) {
      throw e.error ?? e;
    }
  }
}