import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { VipCodeEntity } from '../../domain/entities/vip-code.entity';
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
import { BaseModel } from 'src/core/modules/data/model/base.model';
import { VipCategoryModel } from 'src/modules/transaction/vip-category/data/models/vip-category.model';

@Entity(TABLE_NAME.VIP_CODE)
export class VipCodeModel
  extends BaseModel<VipCodeEntity>
  implements VipCodeEntity
{
  @Column('varchar', { name: 'code' })
  code: string;

  @Column('integer', { name: 'discount', nullable: true })
  discount: number;

  @Column('decimal', { nullable: true })
  discount_value: number;

  @Column('varchar', { name: 'vip_category_id' })
  vip_category_id: string;

  @ManyToOne(() => VipCategoryModel, (model) => model.vip_codes, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  @JoinColumn({ name: 'vip_category_id' })
  vip_category: VipCategoryModel;

  @Column('varchar', { name: 'otp_code', nullable: true })
  otp_code: string;
}
