import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';

export type ActivityType = 'invite_cashback';

export interface ActivityConfig {
  firstOrderRate: number;
  secondOrderRate: number;
  minCashback: number;
  maxCashback: number;
  withdrawThreshold: number;
  maxOrderIndex?: number;
}

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

  @Column({ length: 100, comment: '活动名称' })
  name: string;

  @Index()
  @Column({
    type: 'enum',
    enum: ['invite_cashback'],
    default: 'invite_cashback',
    comment: '活动类型',
  })
  type: ActivityType;

  @Column({ type: 'boolean', default: true, comment: '是否启用' })
  enabled: boolean;

  @ApiProperty({
    description: '活动配置',
    type: 'object',
    additionalProperties: true,
    example: {
      firstOrderRate: 0.05,
      secondOrderRate: 0.005,
      minCashback: 0.01,
      maxCashback: 50,
      withdrawThreshold: 10,
      maxOrderIndex: 2,
    },
  })
  @Column({ type: 'json', comment: '活动配置' })
  config: ActivityConfig;

  @Column({ name: 'start_time', type: 'datetime', nullable: true, comment: '活动开始时间' })
  startTime: Date;

  @Column({ name: 'end_time', type: 'datetime', nullable: true, comment: '活动结束时间' })
  endTime: Date;

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

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