import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';

export type PlayerAssetType = 'skin' | 'room_decor';

@Entity('user_assets')
@Index('idx_user_assets_user_id', ['user_id'])
@Index('idx_user_assets_user_type_asset_unique', ['user_id', 'asset_type', 'asset_id'], { unique: true })
export class PlayerAssets {
  @PrimaryGeneratedColumn({ type: 'bigint', comment: '主键ID' })
  id: bigint;

  @Column({ type: 'bigint', nullable: false, comment: '关联users.id' })
  user_id: bigint;

  @Column({ type: 'varchar', length: 40, nullable: false, comment: '资产类型：skin/room_decor/item/badge等' })
  asset_type: PlayerAssetType;

  @Column({ type: 'varchar', length: 100, nullable: false, comment: '资产ID' })
  asset_id: string;

  @Column({ type: 'varchar', length: 50, nullable: false, default: 'system', comment: '发放来源' })
  source: string;

  @Column({ type: 'json', nullable: true, comment: '资产扩展数据' })
  metadata?: Record<string, unknown> | null;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP', comment: '获得时间' })
  acquired_at: Date;
}
