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

export enum StatutAvenantType {
    PROPOSE = 'propose',
    ACCEPTE = 'accepte',
    REFUSE = 'refuse',
}

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

    @ManyToOne(() => Contrat, { onDelete: 'CASCADE' })
    @JoinColumn({ name: 'id_contrat' })
    contrat: Contrat;

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

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

    @Column({
        type: 'enum',
        enum: StatutAvenantType,
        enumName: 'statut_avenant_type',
        default: StatutAvenantType.PROPOSE,
        name: 'statut'
    })
    statut: StatutAvenantType;

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

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