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

@Entity('acceptations_documents')
export class AcceptationDocument {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ManyToOne(() => Users, { nullable: false, onDelete: 'CASCADE' })
  @JoinColumn({ name: 'id_utilisateur' })
  utilisateur: Users;

  @ManyToOne(() => DocumentLegal, { nullable: true })
  @JoinColumn({ name: 'id_document' })
  document: DocumentLegal | null;

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

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

  @CreateDateColumn({ name: 'accepte_le', type: 'timestamptz' })
  accepteLe: Date;

  @Column({ type: 'inet', nullable: true })
  ip_address: string | null;

  @Column({ type: 'text', nullable: true })
  user_agent: string | null;
}

