import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index, ManyToOne, JoinColumn, Unique } from 'typeorm';
import { User } from './user.entity';
import { MktActivity } from './mkt-activity.entity';

@Entity('mkt_user_invite_stats')
@Unique(['activityId', 'userId'])
export class MktUserInviteStats {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Index()
  @Column({ name: 'activity_id', type: 'bigint', unsigned: true, comment: '活动ID' })
  activityId: number;

  @Index()
  @Column({ name: 'user_id', type: 'bigint', unsigned: true, comment: '用户ID' })
  userId: number;

  @Column({ name: 'invite_code', length: 32, unique: true, comment: '专属邀请码' })
  inviteCode: string;

  @Column({ name: 'total_invites', type: 'int', unsigned: true, default: 0, comment: '累计邀请人数' })
  totalInvites: number;

  @Column({ name: 'total_orders', type: 'int', unsigned: true, default: 0, comment: '累计下单人数' })
  totalOrders: number;

  @Column({ name: 'total_cashback', type: 'decimal', precision: 10, scale: 2, unsigned: true, default: 0, comment: '累计返现金额' })
  totalCashback: number;

  @Column({ name: 'available_balance', type: 'decimal', precision: 10, scale: 2, unsigned: true, default: 0, comment: '可提现余额' })
  availableBalance: number;

  @Column({ name: 'withdrawn_amount', type: 'decimal', precision: 10, scale: 2, unsigned: true, default: 0, comment: '已提现金额' })
  withdrawnAmount: number;

  @ManyToOne(() => MktActivity)
  @JoinColumn({ name: 'activity_id' })
  activity: MktActivity;

  @ManyToOne(() => User)
  @JoinColumn({ name: 'user_id' })
  user: User;

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

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