import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, Index } from 'typeorm';
import { FileMt } from '@d8d/file-module-mt';

@Entity('goods_category')
export class GoodsCategoryMt {
  @PrimaryGeneratedColumn({ unsigned: true })
  id!: number;

  @Index()
  @Column({ name: 'tenant_id', type: 'int', unsigned: true, comment: '租户ID' })
  tenantId!: number;

  @Column({ name: 'name', type: 'varchar', length: 255, comment: '类别名称' })
  name!: string;

  @Column({ name: 'parent_id', type: 'int', unsigned: true, default: 0, comment: '上级id' })
  parentId!: number;

  @Column({ name: 'image_file_id', type: 'int', unsigned: true, nullable: true, comment: '分类图片文件ID' })
  imageFileId!: number | null;

  @Column({ name: 'level', type: 'int', unsigned: true, default: 0, comment: '层级' })
  level!: number;

  @Column({ name: 'state', type: 'smallint', unsigned: true, default: 1, comment: '状态 1可用 2不可用' })
  state!: number;

  @Column({ name: 'created_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP', comment: '创建时间' })
  createdAt!: Date;

  @Column({ name: 'updated_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', comment: '更新时间' })
  updatedAt!: Date;

  @Column({ name: 'created_by', type: 'int', unsigned: true, nullable: true, comment: '创建用户ID' })
  createdBy!: number | null;

  @Column({ name: 'updated_by', type: 'int', unsigned: true, nullable: true, comment: '更新用户ID' })
  updatedBy!: number | null;

  @ManyToOne(() => FileMt, { nullable: true })
  @JoinColumn({ name: 'image_file_id', referencedColumnName: 'id' })
  imageFile!: FileMt | null;
}