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

@Entity('sys_user_role')
export class SysUserRole {
  @PrimaryGeneratedColumn({ name: 'id' })
  id: number;

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

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

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

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

  @UpdateDateColumn({ name: 'update_time', type: 'int' })
  update_time: number;

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

  @Column({ name: 'status', type: 'int', default: 1 })
  status: number;

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

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

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

  getStatusText(): string {
    const statusMap: { [key: number]: string } = { 0: '禁用', 1: '正常' };
    return statusMap[this.status] || '未知';
  }
} 