import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:syncrow_web/utils/color_manager.dart';

class AirQualityDataModel extends Equatable {
  const AirQualityDataModel({
    required this.date,
    required this.data,
  });

  final DateTime date;
  final List<AirQualityPercentageData> data;

  factory AirQualityDataModel.fromJson(Map<String, dynamic> json) {
    return AirQualityDataModel(
      date: DateTime.parse(json['date'] as String),
      data: (json['data'] as List<dynamic>)
          .map(
            (e) => AirQualityPercentageData.fromJson(e as Map<String, dynamic>),
          )
          .toList(),
    );
  }

  static final Map<String, Color> metricColors = {
    'good': ColorsManager.goodGreen.withValues(alpha: 0.7),
    'moderate': ColorsManager.moderateYellow.withValues(alpha: 0.7),
    'unhealthy_sensitive': ColorsManager.poorOrange.withValues(alpha: 0.7),
    'unhealthy': ColorsManager.unhealthyRed.withValues(alpha: 0.7),
    'very_unhealthy': ColorsManager.severePink.withValues(alpha: 0.7),
    'hazardous': ColorsManager.hazardousPurple.withValues(alpha: 0.7),
  };

  @override
  List<Object?> get props => [date, data];
}

class AirQualityPercentageData extends Equatable {
  const AirQualityPercentageData({
    required this.type,
    required this.percentage,
  });

  final String type;
  final double percentage;

  factory AirQualityPercentageData.fromJson(Map<String, dynamic> json) {
    return AirQualityPercentageData(
      type: json['type'] as String? ?? '',
      percentage: (json['percentage'] as num?)?.toDouble() ?? 0,
    );
  }

  @override
  List<Object?> get props => [type, percentage];
}
