import 'package:flutter/material.dart';

class WheelSection {
  final Color color;
  final IconData icon;
  final String prize;
  final int value;

  WheelSection({
    required this.color,
    required this.icon,
    required this.prize,
    required this.value,
  });
}

class PrizeHistory {
  final String prize;
  final DateTime dateTime;
  final int value;
  final Color color;
  final IconData icon;
  final String? gamePrizeId; // Added for API integration

  PrizeHistory({
    required this.prize,
    required this.dateTime,
    required this.value,
    required this.color,
    required this.icon,
    this.gamePrizeId,
  });

  // CopyWith method for updating properties
  PrizeHistory copyWith({
    String? prize,
    DateTime? dateTime,
    int? value,
    Color? color,
    IconData? icon,
    String? gamePrizeId,
  }) {
    return PrizeHistory(
      prize: prize ?? this.prize,
      dateTime: dateTime ?? this.dateTime,
      value: value ?? this.value,
      color: color ?? this.color,
      icon: icon ?? this.icon,
      gamePrizeId: gamePrizeId ?? this.gamePrizeId,
    );
  }

  // Convert to Map for storage/API calls
  Map<String, dynamic> toMap() {
    return {
      'prize': prize,
      'dateTime': dateTime.toIso8601String(),
      'value': value,
      'gamePrizeId': gamePrizeId,
    };
  }

  // Create from Map for loading from storage/API
  factory PrizeHistory.fromMap(
    Map<String, dynamic> map, {
    required Color color,
    required IconData icon,
  }) {
    return PrizeHistory(
      prize: map['prize'] ?? '',
      dateTime: DateTime.tryParse(map['dateTime'] ?? '') ?? DateTime.now(),
      value: map['value'] ?? 0,
      color: color,
      icon: icon,
      gamePrizeId: map['gamePrizeId'],
    );
  }

  // Format date for display
  String get formattedDate {
    return '${dateTime.day.toString().padLeft(2, '0')}/${dateTime.month.toString().padLeft(2, '0')}/${dateTime.year} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}';
  }

  // Get prize category based on value
  String get prizeCategory {
    if (value >= 1000000) return 'Jackpot';
    if (value >= 100000) return 'Big Prize';
    if (value >= 10000) return 'Medium Prize';
    if (value >= 1000) return 'Small Prize';
    return 'Token/Spin';
  }

  // Get prize category color
  Color get categoryColor {
    if (value >= 1000000) return const Color(0xFFFFD700); // Gold
    if (value >= 100000) return const Color(0xFFC0C0C0); // Silver
    if (value >= 10000) return const Color(0xFFCD7F32); // Bronze
    return color; // Default color
  }
}
