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

@Entity('documents_legaux')
export class DocumentLegal {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'varchar', length: 50, nullable: false })
  type: 'cgu' | 'privacy';

  @Column({ type: 'integer', nullable: false })
  version: number;

  @Column({ type: 'varchar', length: 255, nullable: false })
  fichier_nom: string;

  @Column({ type: 'varchar', length: 500, nullable: false })
  fichier_path: string;

  @Column({ type: 'varchar', length: 64, nullable: false })
  fichier_hash: string;

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

  @ManyToOne(() => Users, { nullable: true })
  @JoinColumn({ name: 'televerse_par' })
  televersePar: Users | null;

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

  @Column({ name: 'active_le', type: 'timestamptz', nullable: true })
  activeLe: Date | null;
}

