import {
  Entity, PrimaryGeneratedColumn, Column,
  ManyToOne, JoinColumn, CreateDateColumn
} from 'typeorm';
import { Dossier } from './dossiers.entity';
import { Users } from './users.entity';

@Entity('messages')
export class Message {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ManyToOne(() => Dossier, d => d.messages, { onDelete: 'CASCADE', nullable: false })
  @JoinColumn({ name: 'id_dossier' })
  dossier: Dossier;

  @ManyToOne(() => Users, u => u.messages, { onDelete: 'CASCADE', nullable: false })
  @JoinColumn({ name: 'id_expediteur' })
  sender: Users;

  @Column({ type: 'text', name: 'contenu' })
  content: string;

  @Column({ type: 'boolean', name: 're_redige_par_ia', default: false })
  reRedigeParIA: boolean;

  @CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
  created_at: Date;
}
