import 'package:dio/dio.dart';
import '../../../../core/network/api_endpoints.dart';

class ChatResponseModel {
  final String sessionId;
  final String reply;
  final bool ragUsed;

  const ChatResponseModel({
    required this.sessionId,
    required this.reply,
    this.ragUsed = false,
  });

  factory ChatResponseModel.fromJson(Map<String, dynamic> json) {
    return ChatResponseModel(
      sessionId: (json['session_id'] as String?) ?? '',
      reply: (json['reply'] as String?) ?? '',
      ragUsed: (json['rag_used'] as bool?) ?? false,
    );
  }
}

class ChatRemoteDatasource {
  final Dio _dio;

  ChatRemoteDatasource(this._dio);

  Future<ChatResponseModel> sendMessage({
    required String sessionId,
    required String message,
    String? knowledgeBaseId,
  }) async {
    final response = await _dio.post(
      ApiEndpoints.chat,
      data: {
        'session_id': sessionId,
        'message': message,
        if (knowledgeBaseId != null) 'knowledge_base_id': knowledgeBaseId,
      },
    );
    return ChatResponseModel.fromJson(response.data as Map<String, dynamic>);
  }
}