import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
import { Children } from "./children.entity";
import { Users } from "./users.entity";
import { Parents } from "./parents.entity";

export enum TypeEvenementType {
    ABSENCE_ENFANT = 'absence_enfant',
    CONGE_AM = 'conge_am',
    CONGE_PARENT = 'conge_parent',
    ARRET_MALADIE_AM = 'arret_maladie_am',
    EVENEMENT_RPE = 'evenement_rpe',
}

export enum StatutEvenementType {
    PROPOSE = 'propose',
    VALIDE = 'valide',
    REFUSE = 'refuse',
}

@Entity('evenements')
export class Evenement {
    // Define your columns and relationships here
    @PrimaryGeneratedColumn('uuid')
    id: string;

    @Column({
        type: 'enum',
        enum: TypeEvenementType,
        enumName: 'type_evenement_type',
        name: 'type'
    })
    type: TypeEvenementType;

    @ManyToOne(() => Children, { onDelete: 'CASCADE', nullable: true })
    @JoinColumn({ name: 'id_enfant', referencedColumnName: 'id' })
    child?: Children;

    @ManyToOne(() => Users, { nullable: true })
    @JoinColumn({ name: 'id_am', referencedColumnName: 'id' })
    assistanteMaternelle?: Users;

    @ManyToOne(() => Parents, { nullable: true })
    @JoinColumn({ name: 'id_parent', referencedColumnName: 'user_id' })
    parent?: Parents;

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

    @Column({ type: 'timestamptz', nullable: true, name: 'date_debut' })
    start_date?: Date;

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

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

    @Column({
        type: 'enum',
        enum: StatutEvenementType,
        enumName: 'statut_evenement_type',
        name: 'statut',
        default: StatutEvenementType.PROPOSE
    })
    status: StatutEvenementType;
    
    @Column({type: 'timestamptz', nullable: true, name: 'delai_grace'})
    grace_deadline?: Date;

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

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

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