import {
  Entity, PrimaryGeneratedColumn, Column,
  ManyToOne, OneToMany, CreateDateColumn, UpdateDateColumn, JoinColumn
} from 'typeorm';
import { Parents } from './parents.entity';
import { Children } from './children.entity';
import { Message } from './messages.entity';

export enum StatutDossierType {
  ENVOYE = 'envoye',
  ACCEPTE = 'accepte',
  REFUSE = 'refuse',
  CLOTURE = 'cloture',
}

@Entity('dossiers')
export class Dossier {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ManyToOne(() => Parents, p => p.dossiers, { onDelete: 'CASCADE', nullable: false })
  @JoinColumn({ name: 'id_parent', referencedColumnName: 'user_id' })
  parent: Parents;

  @ManyToOne(() => Children, c => c.dossiers, { onDelete: 'CASCADE', nullable: false })
  @JoinColumn({ name: 'id_enfant', referencedColumnName: 'id' })
  child: Children;

  @Column({ type: 'text', nullable: true, name: 'presentation' })
  presentation?: string;

  @Column({ type: 'varchar', length: 50, nullable: true, name: 'type_contrat' })
  type_contrat?: string;

  @Column({ type: 'boolean', default: false, name: 'repas' })
  meals: boolean;

  @Column({ type: 'numeric', precision: 10, scale: 2, nullable: true, name: 'budget' })
  budget?: number;

  @Column({ type: 'jsonb', nullable: true, name: 'planning_souhaite' })
  desired_schedule?: any;

  @Column({
    type: 'enum',
    enum: StatutDossierType,
    enumName: 'statut_dossier_type',
    default: StatutDossierType.ENVOYE,
    name: 'statut'
  })
  status: StatutDossierType;

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

  @UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
  updated_at: Date;

  @OneToMany(() => Message, m => m.dossier)
  messages: Message[];
}