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

@Entity('mkt_invitations')
export class MktInvitation {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

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

  @Index()
  @Column({ name: 'inviter_id', type: 'bigint', unsigned: true, comment: '邀请人用户ID' })
  inviterId: number;

  @Index()
  @Column({ name: 'invitee_id', type: 'bigint', unsigned: true, unique: true, comment: '被邀请人用户ID' })
  inviteeId: number;

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

  @Column({ length: 100, nullable: true, comment: '小程序scene参数' })
  scene: string;

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

  @ManyToOne(() => User)
  @JoinColumn({ name: 'inviter_id' })
  inviter: User;

  @ManyToOne(() => User)
  @JoinColumn({ name: 'invitee_id' })
  invitee: User;

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