/**
 * StorageBucket Entity
 * Storage bucket configuration with provider and quota settings
 * Compatible with erp-core bucket.entity
 *
 * @module Storage
 */

import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Index,
} from 'typeorm';

export type BucketType = 'public' | 'private' | 'protected';
export type StorageProvider = 'local' | 's3' | 'gcs' | 'azure';

@Entity({ name: 'buckets', schema: 'storage' })
export class StorageBucket {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index({ unique: true })
  @Column({ name: 'name', type: 'varchar', length: 100 })
  name: string;

  @Column({ name: 'description', type: 'text', nullable: true })
  description: string;

  @Column({ name: 'bucket_type', type: 'varchar', length: 30, default: 'private' })
  bucketType: BucketType;

  @Column({ name: 'max_file_size_mb', type: 'int', default: 50 })
  maxFileSizeMb: number;

  @Column({ name: 'allowed_mime_types', type: 'text', array: true, default: [] })
  allowedMimeTypes: string[];

  @Column({ name: 'allowed_extensions', type: 'text', array: true, default: [] })
  allowedExtensions: string[];

  @Column({ name: 'auto_delete_days', type: 'int', nullable: true })
  autoDeleteDays: number;

  @Column({ name: 'versioning_enabled', type: 'boolean', default: false })
  versioningEnabled: boolean;

  @Column({ name: 'max_versions', type: 'int', default: 5 })
  maxVersions: number;

  @Column({ name: 'storage_provider', type: 'varchar', length: 30, default: 'local' })
  storageProvider: StorageProvider;

  @Column({ name: 'storage_config', type: 'jsonb', default: {} })
  storageConfig: Record<string, any>;

  @Column({ name: 'quota_per_tenant_gb', type: 'int', nullable: true })
  quotaPerTenantGb: number;

  @Column({ name: 'is_active', type: 'boolean', default: true })
  isActive: boolean;

  @Column({ name: 'is_system', type: 'boolean', default: false })
  isSystem: boolean;

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

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