// src/entities/product-variant.entity.ts
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany, JoinColumn } from 'typeorm';
import { Product } from '../entity/product';
import { CartItem } from '../entity/cart-item';
import { OrderItem } from '../entity/OrderItem';
import { Wishlist } from '../entity/wishlist';
import { Image } from '../entity/image';

@Entity()
export class ProductVariant {
  @PrimaryGeneratedColumn()
  variant_id?: number;

  @Column({ unique: true })
  sku?: string;

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

  @Column()
  stock_quantity?: number;

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

  @Column('json', { nullable: true })
  dimensions?: { length: number; width: number; height: number };

  @Column({ nullable: true })
  color?: string;

  @Column({ nullable: true })
  material?: string;

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

  @OneToMany(() => CartItem, cartItem => cartItem.variant)
  cartItems?: CartItem[];

  @OneToMany(() => OrderItem, orderItem => orderItem.variant)
  orderItems?: OrderItem[];

  @OneToMany(() => Wishlist, wishlist => wishlist.variant)
  wishlists?: Wishlist[];

  @OneToMany(() => Image, image => image.variant)
  images?: Image[];
}