import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  CreateDateColumn,
} from 'typeorm';
import { AssistanteMaternelle } from './assistantes_maternelles.entity';
import { Children } from './children.entity';
import { Users } from './users.entity';

@Entity('enfants_assistantes_maternelles', { schema: 'public' })
export class AmChildren {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'id_am', type: 'uuid' })
  amId: string;

  @Column({ name: 'id_enfant', type: 'uuid' })
  enfantId: string;

  @Column({ name: 'date_debut', type: 'date' })
  date_debut: Date;

  @Column({ name: 'date_fin', type: 'date', nullable: true })
  date_fin?: Date;

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

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

  @ManyToOne(() => AssistanteMaternelle, (am) => am.amChildren, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'id_am', referencedColumnName: 'user_id' })
  am: AssistanteMaternelle;

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

  @ManyToOne(() => Users, { nullable: true, onDelete: 'SET NULL' })
  @JoinColumn({ name: 'cree_par', referencedColumnName: 'id' })
  createdBy?: Users;
}
