import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { Column, Entity, JoinColumn, OneToOne } from 'typeorm';
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
import { TransactionModel } from './transaction.model';
import { TransactionDemographyEntity } from '../../domain/entities/transaction-graphy.entity';
import { DemographyNationality } from '../../constants';

@Entity(TABLE_NAME.TRANSACTION_DEMOGRAPHY)
export class TransactionDemographyModel
  extends BaseCoreModel<TransactionDemographyEntity>
  implements TransactionDemographyEntity
{
  @Column('int', { default: 0 })
  man: number;

  @Column('int', { default: 0 })
  woman: number;

  @Column('int', { default: 0 })
  teen: number;

  @Column('int', { default: 0 })
  child: number;

  @Column('enum', {
    name: 'nationality',
    enum: DemographyNationality,
    default: DemographyNationality.LOCAL,
  })
  nationality: DemographyNationality;

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

  @OneToOne(() => TransactionModel, (model) => model.demographies, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  @JoinColumn({ name: 'transaction_id' })
  transaction: TransactionModel;
}
