import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { License } from './license.entity';
import { WebstoreCategory } from './webstore-category.entity';

@Entity('webstore_items')
export class WebstoreItem {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

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

  @Column({ type: 'varchar' })
  item_name: string;

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

  @Column({ type: 'decimal', precision: 10, scale: 2 })
  price: number;

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

  @Column({ type: 'varchar', default: 'kit' })
  item_type: string;

  @Column({ type: 'jsonb' })
  delivery_config: Record<string, any>;

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

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

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

  @ManyToOne(() => WebstoreCategory, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'category_id' })
  category: WebstoreCategory;
}
