import { DB_SCHEMA } from 'src/utils';
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { B2bAffiliateAccountProductsEntity } from './B2bAffiliateAccountProducts.entity';

@Entity('b2b_affiliate_accounts', { schema: DB_SCHEMA })
export class B2bAffiliateAccountsEntity {
  @PrimaryGeneratedColumn({ type: 'smallint', name: 'id' })
  id: number;

  @Column('varchar', { name: 'uid', nullable: true, length: 50 })
  uid: string | null;

  @Column('varchar', { name: 'affiliate_name', length: 255 })
  affiliate_name: string;

  @Column('smallint', { name: 'company_portal_id' })
  company_portal_id: number;

  @Column('tinyint', {
    name: 'status',
    comment: '1 => Active, 2 => Inactive',
    width: 1,
    default: () => "'1'",
  })
  status: boolean;

  @Column('smallint', { name: 'by_user' })
  by_user: number;

  @Column('datetime', {
    name: 'created_on',
    default: () => 'CURRENT_TIMESTAMP',
  })
  created_on: Date;

  @Column('datetime', {
    name: 'updated_on',
    default: () => 'CURRENT_TIMESTAMP',
  })
  updated_on: Date;

  @OneToMany(
    () => B2bAffiliateAccountProductsEntity,
    (products) => products.b2b_account,
  )
  products: B2bAffiliateAccountProductsEntity[];
}
