import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Message } from './message.entity';

@Injectable()
export class ChatService {
  constructor(
    @InjectRepository(Message)
    private messageRepository: Repository<Message>,
  ) {}

  async createMessage(data: { content: string; sender: string }): Promise<Message> {
    const message = this.messageRepository.create({
      content: data.content,
      sender: data.sender,
      timestamp: new Date(),
    });

    return this.messageRepository.save(message);
  }
}