import { Entity, PrimaryColumn, Column, OneToOne, OneToMany, JoinColumn } from 'typeorm';
import { Users } from './users.entity';
import { AmChildren } from './am_children.entity';

@Entity('assistantes_maternelles')
export class AssistanteMaternelle {
  // PK = FK vers utilisateurs.id
  @PrimaryColumn('uuid', { name: 'id_utilisateur' })
  user_id: string;

  @OneToOne(() => Users, (user) => user.assistanteMaternelle, {
    onDelete: 'CASCADE',
  })
  @JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
  user: Users;

  @Column({ name: 'numero_agrement', length: 50, nullable: true })
  approval_number?: string;

  @Column({ name: 'nir_chiffre', length: 15, nullable: true })
  nir?: string;

  @Column({ name: 'nb_max_enfants', type: 'int', nullable: true })
  max_children?: number;

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

  @Column({
    name: 'disponible',
    type: 'boolean',
    default: true,
    nullable: true,
  })
  available?: boolean;

  @Column({ name: 'ville_residence', length: 100, nullable: true })
  residence_city?: string;

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

  @Column( { name: 'annee_experience', type: 'smallint', nullable: true })
  years_experience?: number;
  
  @Column( { name: 'specialite', length: 100, nullable: true })
  specialty?: string;

  @Column( { name: 'place_disponible', type: 'integer', nullable: true })
  places_available?: number;

  /** Numéro de dossier (format AAAA-NNNNNN), même valeur que sur utilisateurs (ticket #103) */
  @Column({ name: 'numero_dossier', length: 20, nullable: true })
  numero_dossier?: string;

  @OneToMany(() => AmChildren, (ac) => ac.am)
  amChildren: AmChildren[];
}
