/**
 * Reward types enumeration
 */
export enum RewardType {
  LEARNING_HOURS = 'learning_hours',
  PERFORMANCE_BONUS = 'performance_bonus',
  COMPLETION_REWARD = 'completion_reward',
  CONSISTENCY_REWARD = 'consistency_reward'
}

/**
 * Reward sources enumeration
 */
export enum RewardSource {
  COURSE_COMPLETION = 'course_completion',
  EXAM_PASS = 'exam_pass',
  LEARNING_TIME = 'learning_time',
  STREAK_ACHIEVEMENT = 'streak_achievement',
  PERFORMANCE_MILESTONE = 'performance_milestone'
}

/**
 * Reward status enumeration
 */
export enum RewardStatus {
  PENDING = 'pending',
  APPROVED = 'approved',
  PAID = 'paid',
  REJECTED = 'rejected'
}

/**
 * Base reward interface
 */
export interface BaseReward {
  id: string;
  userId: string;
  type: RewardType;
  source: RewardSource;
  amount: number;
  currency: string;
  status: RewardStatus;
  description: string;
  metadata?: Record<string, any>;
  createdAt: Date;
  updatedAt: Date;
  approvedAt?: Date;
  paidAt?: Date;
  approvedBy?: string;
  payrollBatchId?: string;
}

/**
 * Learning hours reward
 */
export interface LearningHoursReward extends BaseReward {
  type: RewardType.LEARNING_HOURS;
  hoursLogged: number;
  ratePerHour: number;
  sessionIds: string[];
}

/**
 * Performance bonus reward
 */
export interface PerformanceBonusReward extends BaseReward {
  type: RewardType.PERFORMANCE_BONUS;
  performanceScore: number;
  bonusMultiplier: number;
  achievementId: string;
}

/**
 * Completion reward
 */
export interface CompletionReward extends BaseReward {
  type: RewardType.COMPLETION_REWARD;
  completedItemId: string;
  completedItemType: 'course' | 'exam' | 'module';
  completionScore?: number;
}

/**
 * Consistency reward
 */
export interface ConsistencyReward extends BaseReward {
  type: RewardType.CONSISTENCY_REWARD;
  streakDays: number;
  streakType: 'daily_login' | 'daily_learning' | 'weekly_goals';
  bonusMultiplier: number;
}

/**
 * Union type for all reward types
 */
export type Reward = LearningHoursReward | PerformanceBonusReward | CompletionReward | ConsistencyReward;

/**
 * Reward calculation input
 */
export interface RewardCalculationInput {
  userId: string;
  type: RewardType;
  source: RewardSource;
  baseAmount?: number;
  metadata: Record<string, any>;
}

/**
 * Reward calculation result
 */
export interface RewardCalculationResult {
  amount: number;
  currency: string;
  description: string;
  metadata: Record<string, any>;
}

/**
 * Reward configuration
 */
export interface RewardConfig {
  learningHours: {
    enabled: boolean;
    ratePerHour: number;
    maxHoursPerDay: number;
    currency: string;
  };
  performanceBonus: {
    enabled: boolean;
    baseAmount: number;
    multipliers: {
      excellent: number; // 90-100%
      good: number;      // 80-89%
      average: number;   // 70-79%
    };
    currency: string;
  };
  completionReward: {
    enabled: boolean;
    courseCompletion: number;
    examPass: number;
    moduleCompletion: number;
    currency: string;
  };
  consistencyReward: {
    enabled: boolean;
    dailyStreak: {
      baseAmount: number;
      multiplierPerWeek: number;
      maxMultiplier: number;
    };
    weeklyGoals: {
      baseAmount: number;
      multiplier: number;
    };
    currency: string;
  };
}

/**
 * Default reward configuration
 */
export const defaultRewardConfig: RewardConfig = {
  learningHours: {
    enabled: true,
    ratePerHour: 50000, // IDR
    maxHoursPerDay: 8,
    currency: 'IDR'
  },
  performanceBonus: {
    enabled: true,
    baseAmount: 100000, // IDR
    multipliers: {
      excellent: 2.0,
      good: 1.5,
      average: 1.0
    },
    currency: 'IDR'
  },
  completionReward: {
    enabled: true,
    courseCompletion: 200000, // IDR
    examPass: 150000, // IDR
    moduleCompletion: 50000, // IDR
    currency: 'IDR'
  },
  consistencyReward: {
    enabled: true,
    dailyStreak: {
      baseAmount: 25000, // IDR
      multiplierPerWeek: 0.1,
      maxMultiplier: 3.0
    },
    weeklyGoals: {
      baseAmount: 100000, // IDR
      multiplier: 1.5
    },
    currency: 'IDR'
  }
};