import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn } from 'typeorm';
import { SysUser } from './SysUser';

@Entity('sys_user_log')
export class SysUserLog {
  @PrimaryGeneratedColumn({ type: 'int', unsigned: true })
  id: number;

  @Column({ type: 'varchar', length: 50, default: '' })
  ip: string;

  @Column({ type: 'int', default: 0 })
  site_id: number;

  @Column({ type: 'int', unsigned: true, default: 0 })
  uid: number;

  @Column({ type: 'varchar', length: 255, default: '' })
  username: string;

  @Column({ type: 'varchar', length: 255 })
  operation: string;

  @Column({ type: 'varchar', length: 300 })
  url: string;

  @Column({ type: 'longtext', nullable: true })
  params: string;

  @Column({ type: 'varchar', length: 32, default: '' })
  type: string;

  @CreateDateColumn({ type: 'int', unsigned: true })
  create_time: number;

  // 关联关系
  @ManyToOne(() => SysUser, user => user.user_logs)
  @JoinColumn({ name: 'uid', referencedColumnName: 'uid' })
  user: SysUser;

  // 业务逻辑方法 - 与 PHP 项目保持一致
  getCreateTimeText(): string {
    return this.create_time ? new Date(this.create_time * 1000).toLocaleString('zh-CN') : '';
  }
} 