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

export enum StatutValidationType {
    EN_ATTENTE = 'en_attente',
    VALIDE = 'valide',
    REFUSE = 'refuse',
}

@Entity('validations')
export class Validation {
    @PrimaryGeneratedColumn('uuid')
    id: string;

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

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

    @Column({
        type: 'enum',
        enum: StatutValidationType,
        enumName: 'statut_validation_type',
        name: 'statut',
        default: StatutValidationType.EN_ATTENTE
    })
    status: StatutValidationType;

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

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

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

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