import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, Check } from 'typeorm';
import { License } from './license.entity';
import { User } from './user.entity';

@Entity('migration_exports')
@Check(`"export_type" IN ('full', 'config_only', 'store_only')`)
export class MigrationExport {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'uuid' })
  license_id: string;

  @Column({ type: 'varchar', length: 20, default: 'full' })
  export_type: string;

  @Column({ type: 'text' })
  storage_path: string;

  @Column({ type: 'bigint', default: 0 })
  file_size_bytes: number;

  @Column({ type: 'uuid' })
  created_by: string;

  @Column({ type: 'timestamptz' })
  expires_at: Date;

  @Column({ type: 'timestamptz', default: () => 'NOW()' })
  created_at: Date;

  @ManyToOne(() => License, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'license_id' })
  license: License;

  @ManyToOne(() => User)
  @JoinColumn({ name: 'created_by' })
  creator: User;
}
