import { ApiHideProperty, ApiProperty } from '@nestjs/swagger';
import { Column, Entity, JoinTable, ManyToMany, OneToMany, Relation } from 'typeorm';
import { CommonEntity } from '~/common/entity/common.entity';
import { Storage } from '../tools/storage/storage.entity';
import { ProductEntity } from '../product/product.entity';

@Entity({ name: 'company' })
export class CompanyEntity extends CommonEntity {
  @Column({
    name: 'name',
    type: 'varchar',
    unique: true,
    length: 255,
    comment: '公司名称'
  })
  @ApiProperty({ description: '公司名称' })
  name: string;

  @Column({ name: 'is_delete', type: 'tinyint', default: 0, comment: '是否删除' })
  @ApiProperty({ description: '删除状态:0未删除,1已删除' })
  isDelete: number;

  @ApiHideProperty()
  @OneToMany(() => ProductEntity, product => product.company)
  products: Relation<ProductEntity[]>;

  @ManyToMany(() => Storage, storage => storage.companys)
  @JoinTable({
    name: 'company_storage',
    joinColumn: { name: 'company_id', referencedColumnName: 'id' },
    inverseJoinColumn: { name: 'file_id', referencedColumnName: 'id' }
  })
  files: Relation<Storage[]>;
}