import type { UiMessage } from '@/contexts';
import type { Message } from '@/components/ui/chat-message';

export function convertToShadcnMessage(message: UiMessage): Message {
  const isAi = ['ai', 'system', 'tool'].includes(message.sender_type);
  const role = isAi ? 'assistant' : 'user';

  return {
    id: message.id,
    role: role,
    content: message.content,
    createdAt: new Date(message.send_at),
  };
}

/**
 * 批量转换消息列表
 */
export function convertMessagesToShadcn(messages: UiMessage[]): Message[] {
  return messages.map(convertToShadcnMessage);
}
