import { UserEntity } from 'src/modules/user/entities/user.entity';
import { ProductEntity } from './product.entity';
import {
  BaseEntity,
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';

export enum ProductNotifQuantityStatus {
  pending = 'pending',
  done = 'done',
}
@Index('fk_product_notif_quantities_products1_idx', ['productId'], {})
@Index('fk_product_notif_quantities_users1_idx', ['userId'], {})
@Entity('product_notif_quantities')
export class ProductNotifQuantityEntity extends BaseEntity {
  @PrimaryGeneratedColumn({ type: 'int', name: 'id' })
  id: number;

  @Column('char', { name: 'userId', length: 36 })
  userId: string;

  @Column('char', { name: 'productId', length: 36 })
  productId: string;

  @Column('enum', {
    name: 'status',
    enum: ProductNotifQuantityStatus,
    default: () => ProductNotifQuantityStatus.pending,
  })
  status: ProductNotifQuantityStatus;

  @Column('datetime', { name: 'createdAt' })
  createdAt: Date;

  @Column('datetime', { name: 'updatedAt' })
  updatedAt: Date;

  @ManyToOne(
    () => ProductEntity,
    (products) => products.productNotifQuantities,
    {
      onDelete: 'NO ACTION',
      onUpdate: 'CASCADE',
    },
  )
  @JoinColumn([{ name: 'productId', referencedColumnName: 'id' }])
  product: ProductEntity;

  @ManyToOne(() => UserEntity, (users) => users.productNotifQuantities, {
    onDelete: 'NO ACTION',
    onUpdate: 'CASCADE',
  })
  @JoinColumn([{ name: 'userId', referencedColumnName: 'id' }])
  user: UserEntity;
}
