// src/entities/review.entity.ts
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { User } from '../entity/Users';
import { Product } from '../entity/product';

@Entity()
export class Review {
  @PrimaryGeneratedColumn()
  review_id?: number;

  @Column({ type: 'int' })
  rating?: number; // 1-5

  @Column({ type: 'text', nullable: true })
  comment?: string;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  created_at?: Date;

  // Relations
  @ManyToOne(() => User, user => user.reviews)
  @JoinColumn({ name: 'user_id' })
  user?: User;

  @ManyToOne(() => Product, product => product.reviews)
  @JoinColumn({ name: 'product_id' })
  product?: Product;
}