import {
  Column,
  CreateDateColumn,
  Entity,
  OneToMany,
  PrimaryColumn,
  UpdateDateColumn,
} from 'typeorm';
import { Message } from './message.entity';

@Entity('conversations')
export class Conversation {
  @PrimaryColumn({ type: 'varchar', length: 400 })
  id: string;

  @Column({ nullable: true })
  name: string;

  @Column({ nullable: false })
  type: 'group' | 'personal';

  @CreateDateColumn()
  created_at: Date;

  @UpdateDateColumn()
  updated_at: Date;

  @OneToMany(() => Message, (message) => message.conversation)
  messages: Message[];
}
