import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index, OneToOne } from 'typeorm';
import { Merchant } from './merchant.entity';

@Entity('sellers')
export class Seller {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Column({ length: 20, unique: true, comment: '手机号' })
  phone: string;

  @Column({ length: 255, nullable: true, select: false, comment: '密码(bcrypt哈希)' })
  password?: string;

  @Column({ length: 50, name: 'contact_name', comment: '联系人姓名' })
  contactName: string;

  @Column({ length: 100, nullable: true, comment: '邮箱' })
  email: string;

  @Index()
  @Column({ type: 'enum', enum: ['active', 'frozen', 'deleted'], default: 'active', comment: '状态' })
  status: 'active' | 'frozen' | 'deleted';

  @Column({ type: 'datetime', nullable: true, name: 'last_login_at', comment: '最后登录时间' })
  lastLoginAt: Date;

  @Column({ length: 50, nullable: true, name: 'last_login_ip', comment: '最后登录IP' })
  lastLoginIp: string;

  @OneToOne(() => Merchant, merchant => merchant.seller)
  merchant: Merchant;

  @CreateDateColumn({ name: 'created_at', comment: '创建时间' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', comment: '更新时间' })
  updatedAt: Date;
}
