import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, Index } from 'typeorm';
import { Platform } from '@d8d/allin-platform-module/entities';

@Entity('employer_company')
@Index('idx_company_name_platform', ['companyName', 'platformId'], { unique: true })
export class Company {
  @PrimaryGeneratedColumn({
    name: 'company_id',
    type: 'int',
    unsigned: true,
    comment: '公司ID'
  })
  id!: number;

  @Column({
    name: 'platform_id',
    type: 'int',
    unsigned: true,
    nullable: true,
    comment: '平台ID'
  })
  platformId!: number | null;

  @Column({
    name: 'company_name',
    type: 'varchar',
    length: 100,
    nullable: false,
    comment: '公司名称'
  })
  companyName!: string;

  @Column({
    name: 'contact_person',
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '联系人'
  })
  contactPerson!: string | null;

  @Column({
    name: 'contact_phone',
    type: 'varchar',
    length: 20,
    nullable: true,
    comment: '联系电话'
  })
  contactPhone!: string | null;

  @Column({
    name: 'contact_email',
    type: 'varchar',
    length: 100,
    nullable: true,
    comment: '联系邮箱'
  })
  contactEmail!: string | null;

  @Column({
    name: 'address',
    type: 'varchar',
    length: 200,
    nullable: true,
    comment: '地址'
  })
  address!: string | null;

  @Column({
    name: 'status',
    type: 'int',
    default: 1,
    comment: '状态：1-正常，0-禁用'
  })
  status!: number;

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

  @Column({
    name: 'update_time',
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
    comment: '更新时间'
  })
  updateTime!: Date;

  @ManyToOne(() => Platform, { eager: true })
  @JoinColumn({ name: 'platform_id' })
  platform?: Platform;
}