import { describe, it, expect, beforeEach } from 'vitest';
import { useChatStore, MessageSender, MessageStatus } from '../chat-store';

/**
 * EN: Chat store unit tests
 * VI: Unit tests cho chat store
 */
describe('ChatStore', () => {
  beforeEach(() => {
    // EN: Reset store state before each test / VI: Reset state store trước mỗi test
    useChatStore.setState({
      conversations: [],
      messages: {},
      currentConversationId: null,
      isLoading: false,
      error: null,
    });
  });

  it('initializes with default state', () => {
    const state = useChatStore.getState();
    expect(state.conversations).toEqual([]);
    expect(state.messages).toEqual({});
    expect(state.currentConversationId).toBeNull();
  });

  it('creates new conversation', () => {
    const createConversation = useChatStore.getState().createConversation;
    const conversationId = createConversation('Test Conversation');
    
    expect(conversationId).toBeDefined();
    const state = useChatStore.getState();
    expect(state.conversations.length).toBe(1);
    expect(state.conversations[0].title).toBe('Test Conversation');
  });

  it('selects conversation', () => {
    const createConversation = useChatStore.getState().createConversation;
    const selectConversation = useChatStore.getState().selectConversation;
    
    const conversationId = createConversation('Test');
    selectConversation(conversationId);
    
    const state = useChatStore.getState();
    expect(state.currentConversationId).toBe(conversationId);
  });
});
