import 'package:hmg_qline/constants/app_constants.dart';

class WeathersWidgetModel {
  int? id;
  String? headline;
  double? maxTemp;
  double? minTemp;
  String? iconPhrase;
  String? forecastDate;
  int? cityID;
  String? forecastDay;
  String? createDateTime;
  double? windSpeed;
  String? windDirection;
  double? windDegrees;
  String? weatherIconPathLeft;
  String? weatherIconPathRight;

  WeathersWidgetModel({
    this.id,
    this.headline,
    this.maxTemp,
    this.minTemp,
    this.iconPhrase,
    this.forecastDate,
    this.cityID,
    this.forecastDay,
    this.createDateTime,
    this.windSpeed,
    this.windDirection,
    this.windDegrees,
    this.weatherIconPathLeft,
    this.weatherIconPathRight,
  });

  WeathersWidgetModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    headline = json['headline'];
    maxTemp = json['maxTemp'] ?? "42.2";
    minTemp = json['minTemp'] ?? "31.7";
    iconPhrase = json['iconPhrase'] ?? "Mostly sunny";
    forecastDate = json['forecastDate'];
    cityID = json['cityID'];
    forecastDay = json['forecastDay'];
    createDateTime = json['createDateTime'];
    windSpeed = json['windSpeed'];
    windDirection = json['windDirection'];
    windDegrees = json['windDegrees'];
    weatherIconPathLeft = getWeatherIconPath(json['iconPhrase'], true);
    weatherIconPathRight = getWeatherIconPath(json['iconPhrase'], false);
  }

  String getWeatherIconPath(String iconPhrase, bool isLeft) {
    if (iconPhrase == "Rain" || iconPhrase == "Showers" || iconPhrase == "ThunderStorms") {
      return isLeft ? AppAssets.rainyLeftIcon : AppAssets.rainyRightIcon;
    } else if (iconPhrase == "Hot") {
      return isLeft ? AppAssets.hotLeftIcon : AppAssets.hotRightIcon;
    } else if (iconPhrase == "Windy") {
      return isLeft ? AppAssets.windyLeftIcon : AppAssets.windyRightIcon;
    } else if (iconPhrase == "Cloudy" || iconPhrase == "Mostly cloudy" || iconPhrase == "Intermittent clouds") {
      return isLeft ? AppAssets.cloudyLeftIcon : AppAssets.cloudyRightIcon;
    } else if (iconPhrase == "Sunny" || iconPhrase == "Mostly sunny" || iconPhrase == "Partly sunny" || iconPhrase == "Hazy sunshine") {
      return isLeft ? AppAssets.sunnyLeftIcon : AppAssets.sunnyRightIcon;
    } else {
      return AppAssets.weatherIcon;
    }
  }

  @override
  String toString() {
    return 'WeathersWidgetModel{id: $id, headline: $headline, maxTemp: $maxTemp, minTemp: $minTemp, iconPhrase: $iconPhrase, forecastDate: $forecastDate, cityID: $cityID, forecastDay: $forecastDay, createDateTime: $createDateTime, windSpeed: $windSpeed, windDirection: $windDirection, windDegrees: $windDegrees, weatherIconPathLeft: $weatherIconPathLeft, weatherIconPathRight: $weatherIconPathRight}';
  }
}
