import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';

// 定义 Permission 类型
export type Permission = string;

@Entity({ name: 'roles_mt' })
export class RoleMt {
  @PrimaryGeneratedColumn()
  id!: number;

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

  @Column({ type: 'varchar', length: 50 })
  name!: string;

  @Column({ type: 'text', nullable: true })
  description!: string | null;

  @Column({ type: 'simple-array', nullable: false })
  permissions: Permission[] = [];

  @CreateDateColumn({ name: 'created_at', type: 'timestamp' })
  createdAt!: Date;

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
  updatedAt!: Date;

  constructor(partial?: Partial<RoleMt>) {
    Object.assign(this, partial);
    if (!this.permissions) {
      this.permissions = [];
    }
  }
}

