import 'package:equatable/equatable.dart';

class ChatMessage extends Equatable {
  final String id;
  final String text;
  final bool isUser;
  final bool isTyping;
  final bool ragUsed;
  final DateTime timestamp;

  const ChatMessage({
    required this.id,
    required this.text,
    this.isUser = false,
    this.isTyping = false,
    this.ragUsed = false,
    required this.timestamp,
  });

  @override
  List<Object?> get props => [id];
}

class ChatState extends Equatable {
  final List<ChatMessage> messages;
  final bool isTyping;
  final int? rateLimitSeconds;
  final String? selectedKbId;
  final String sessionId;
  final List<String> knowledgeBases;

  const ChatState({
    this.messages = const [],
    this.isTyping = false,
    this.rateLimitSeconds,
    this.selectedKbId,
    required this.sessionId,
    this.knowledgeBases = const [],
  });

  bool get isRateLimited => rateLimitSeconds != null && rateLimitSeconds! > 0;

  ChatState copyWith({
    List<ChatMessage>? messages,
    bool? isTyping,
    int? Function()? rateLimitSeconds,
    String? Function()? selectedKbId,
    List<String>? knowledgeBases,
  }) {
    return ChatState(
      messages: messages ?? this.messages,
      isTyping: isTyping ?? this.isTyping,
      rateLimitSeconds:
          rateLimitSeconds != null ? rateLimitSeconds() : this.rateLimitSeconds,
      selectedKbId:
          selectedKbId != null ? selectedKbId() : this.selectedKbId,
      sessionId: sessionId,
      knowledgeBases: knowledgeBases ?? this.knowledgeBases,
    );
  }

  @override
  List<Object?> get props =>
      [messages, isTyping, rateLimitSeconds, selectedKbId, knowledgeBases];
}