import {
  BaseEntity,
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
} from 'typeorm';
import { MakerBrandEntity } from '../../car/entities/maker-brand.entity';
import { ProductEntity } from './product.entity';

@Index('makerBrandId', ['makerBrandId'], {})
@Entity('maker_brand_product_mapping1s')
export class ProductMakerBrandMappingEntity extends BaseEntity {
  @Column('int', { name: 'wagePrice', nullable: true })
  wagePrice: number | null;

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

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

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

  @Column('int', { primary: true, name: 'makerBrandId' })
  makerBrandId: number;

  /**
   * Relations
   */
  @ManyToOne(() => ProductEntity, (products) => products.makerBrandMappings, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  @JoinColumn([{ name: 'productId', referencedColumnName: 'id' }])
  product: ProductEntity;

  @ManyToOne(
    () => MakerBrandEntity,
    (makerbrands) => makerbrands.productMappings,
    { onDelete: 'CASCADE', onUpdate: 'CASCADE' },
  )
  @JoinColumn([{ name: 'makerBrandId', referencedColumnName: 'id' }])
  makerBrand: MakerBrandEntity;
}
