// src/entities/discount.entity.ts
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { Category } from '../entity/category';
import { Product } from '../entity/product';

export enum DiscountType {
  PERCENTAGE = 'percentage',
  FIXED = 'fixed'
}

@Entity()
export class Discount {
  @PrimaryGeneratedColumn()
  discount_id?: number;

  @Column()
  name?: string;

  @Column({
    type: 'enum',
    enum: DiscountType
  })
  type?: DiscountType;

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

  @Column({ type: 'timestamp' })
  start_date?: Date;

  @Column({ type: 'timestamp', nullable: true })
  end_date?: Date;

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

  // Relations (only one of these will be set based on applies_to)
  @ManyToOne(() => Category, { nullable: true })
  @JoinColumn({ name: 'category_id' })
  category?: Category;

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