import 'package:equatable/equatable.dart';

class RangeOfAqi extends Equatable {
  final DateTime date;
  final List<RangeOfAqiValue> data;

  const RangeOfAqi({
    required this.data,
    required this.date,
  });

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

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

class RangeOfAqiValue extends Equatable {
  final String type;
  final double min;
  final double average;
  final double max;

  const RangeOfAqiValue({
    required this.type,
    required this.min,
    required this.average,
    required this.max,
  });

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

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