import { BaseEntity } from '@edr/api-common';
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { FileRecord } from '../../files/entities/file.entity';

/**
 * A reusable signature that belongs to a single user (customer or staff).
 * Captured once and applied to many booking contracts so the signer does not
 * have to redraw it every time. One active saved signature per user.
 */
@Entity({ schema: 'freight', name: 'saved_signatures' })
@Index(['userId'], { unique: true })
export class SavedSignature extends BaseEntity {
  @Column({ name: 'user_id', type: 'uuid' })
  userId!: string;

  @Column({ name: 'signer_display_name', type: 'varchar', length: 200 })
  signerDisplayName!: string;

  @Column({ name: 'signature_file_id', type: 'uuid', nullable: true })
  signatureFileId?: string | null;

  @ManyToOne(() => FileRecord, { nullable: true })
  @JoinColumn({ name: 'signature_file_id' })
  signatureFile?: FileRecord | null;
}
