summaryrefslogtreecommitdiffstats
path: root/lib/data/models/vehicle.dart
blob: f27b750803a29bb97aafb2d0b91c0d35b5b204a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import 'dart:convert';

import '../../export.dart';

@immutable
class Vehicle {
  final double speed;
  final double insideTemperature;
  final double outsideTemperature;
  final int range;
  final double fuelLevel;
  final int mediaVolume;
  final bool isChildLockActiveLeft;
  final bool isChildLockActiveRight;
  final int engineSpeed;
  final int frontLeftTire;
  final int frontRightTire;
  final int rearLeftTire;
  final int rearRightTire;
  final bool isAirConditioningActive;
  final bool isFrontDefrosterActive;
  final bool isRearDefrosterActive;
  final bool isRecirculationActive;
  final int fanSpeed;

  const Vehicle(
      this.speed,
      this.insideTemperature,
      this.outsideTemperature,
      this.range,
      this.fuelLevel,
      this.mediaVolume,
      this.isChildLockActiveLeft,
      this.isChildLockActiveRight,
      this.engineSpeed,
      this.frontLeftTire,
      this.frontRightTire,
      this.rearLeftTire,
      this.rearRightTire,
      this.isAirConditioningActive,
      this.isFrontDefrosterActive,
      this.isRearDefrosterActive,
      this.isRecirculationActive,
      this.fanSpeed);

  const Vehicle.initial()
      : speed = 0,
        insideTemperature = 0,
        outsideTemperature = 0,
        range = 0,
        fuelLevel = 0,
        mediaVolume = 50,
        isChildLockActiveLeft = false,
        isChildLockActiveRight = true,
        engineSpeed = 0,
        frontLeftTire = 33,
        frontRightTire = 31,
        rearLeftTire = 31,
        rearRightTire = 32,
        isAirConditioningActive = false,
        isFrontDefrosterActive = false,
        isRearDefrosterActive = false,
        isRecirculationActive = false,
        fanSpeed = 0;

  const Vehicle.initialForDebug()
      : speed = 60,
        insideTemperature = 25,
        outsideTemperature = 32.0,
        range = 21,
        fuelLevel = 49.5,
        mediaVolume = 50,
        isChildLockActiveLeft = false,
        isChildLockActiveRight = true,
        engineSpeed = 6500,
        frontLeftTire = 33,
        frontRightTire = 31,
        rearLeftTire = 31,
        rearRightTire = 32,
        isAirConditioningActive = false,
        isFrontDefrosterActive = false,
        isRearDefrosterActive = false,
        isRecirculationActive = false,
        fanSpeed = 0;

  Vehicle copyWith(
      {double? speed,
      double? insideTemperature,
      double? outsideTemperature,
      int? range,
      double? fuelLevel,
      int? mediaVolume,
      bool? isChildLockActiveLeft,
      bool? isChildLockActiveRight,
      int? engineSpeed,
      int? frontLeftTire,
      int? frontRightTire,
      int? rearLeftTire,
      int? rearRightTire,
      bool? isAirConditioningActive,
      bool? isFrontDefrosterActive,
      bool? isRearDefrosterActive,
      bool? isRecirculationActive,
      int? fanSpeed}) {
    return Vehicle(
        speed ?? this.speed,
        insideTemperature ?? this.insideTemperature,
        outsideTemperature ?? this.outsideTemperature,
        range ?? this.range,
        fuelLevel ?? this.fuelLevel,
        mediaVolume ?? this.mediaVolume,
        isChildLockActiveLeft ?? this.isChildLockActiveLeft,
        isChildLockActiveRight ?? this.isChildLockActiveRight,
        engineSpeed ?? this.engineSpeed,
        frontLeftTire ?? this.frontLeftTire,
        frontRightTire ?? this.frontRightTire,
        rearLeftTire ?? this.rearLeftTire,
        rearRightTire ?? this.rearRightTire,
        isAirConditioningActive ?? this.isAirConditioningActive,
        isFrontDefrosterActive ?? this.isFrontDefrosterActive,
        isRearDefrosterActive ?? this.isRearDefrosterActive,
        isRecirculationActive ?? this.isRecirculationActive,
        fanSpeed ?? this.fanSpeed);
  }

  Map<String, dynamic> toMap() {
    return {
      'speed': speed,
      'insideTemperature': insideTemperature,
      'outsideTemperature': outsideTemperature,
      'range': range,
      'fuelLevel': fuelLevel,
      'mediaVolume': mediaVolume,
      'isChildLockActiveLeft': isChildLockActiveLeft,
      'isChildLockActiveRight': isChildLockActiveRight,
      'engineSpeed': engineSpeed,
      'frontLeftTire': frontLeftTire,
      'frontRightTire': frontRightTire,
      'rearLeftTire': rearLeftTire,
      'rearRightTire': rearRightTire,
      'isAirConditioningActive': isAirConditioningActive,
      'isFrontDefrosterActive': isFrontDefrosterActive,
      'isRearDefrosterActive': isRearDefrosterActive,
      'isRecirculationActive': isRecirculationActive,
      'fanSpeed': fanSpeed
    };
  }

  factory Vehicle.fromMap(Map<String, dynamic> map) {
    return Vehicle(
      map['speed']?.toDouble() ?? 0.0,
      map['insideTemperature']?.toDouble() ?? 0.0,
      map['outsideTemperature']?.toDouble() ?? 0.0,
      map['range']?.toInt() ?? 0,
      map['fuelLevel']?.toDouble() ?? 0.0,
      map['mediaVolume']?.toInt() ?? 0,
      map['isChildLockActiveLeft'] ?? false,
      map['isChildLockActiveRight'] ?? false,
      map['engineSpeed']?.toInt() ?? 0,
      map['frontLeftTire']?.toInt() ?? 0,
      map['frontRightTire']?.toInt() ?? 0,
      map['rearLeftTire']?.toInt() ?? 0,
      map['rearRightTire']?.toInt() ?? 0,
      map['isAirConditioningActive'] ?? false,
      map['isFrontDefrosterActive'] ?? false,
      map['isRearDefrosterActive'] ?? false,
      map['isRecirculationActive'] ?? false,
      map['fanSpeed'] ?? 0,
    );
  }

  String toJson() => json.encode(toMap());

  factory Vehicle.fromJson(String source) =>
      Vehicle.fromMap(json.decode(source));

  @override
  String toString() {
    return 'Vehicle(speed: $speed, insideTemperature: $insideTemperature, outsideTemperature: $outsideTemperature, range: $range, fuelLevel: $fuelLevel, mediaVolume: $mediaVolume, isChildLockActiveLeft: $isChildLockActiveLeft, isChildLockActiveRight: $isChildLockActiveRight, engineSpeed: $engineSpeed, frontLeftTire: $frontLeftTire, frontRightTire: $frontRightTire, rearLeftTire: $rearLeftTire, rearRightTire: $rearRightTire, isAirConditioningActive: $isAirConditioningActive, isFrontDefrosterActive: $isFrontDefrosterActive, isRearDefrosterActive: $isRearDefrosterActive, isRecirculationActive: $isRecirculationActive,fanSpeed:$fanSpeed)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is Vehicle &&
        other.speed == speed &&
        other.insideTemperature == insideTemperature &&
        other.outsideTemperature == outsideTemperature &&
        other.range == range &&
        other.fuelLevel == fuelLevel &&
        other.mediaVolume == mediaVolume &&
        other.isChildLockActiveLeft == isChildLockActiveLeft &&
        other.isChildLockActiveRight == isChildLockActiveRight &&
        other.engineSpeed == engineSpeed &&
        other.frontLeftTire == frontLeftTire &&
        other.frontRightTire == frontRightTire &&
        other.rearLeftTire == rearLeftTire &&
        other.rearRightTire == rearRightTire &&
        other.isAirConditioningActive == isAirConditioningActive &&
        other.isFrontDefrosterActive == isFrontDefrosterActive &&
        other.isRearDefrosterActive == isRearDefrosterActive &&
        other.isRecirculationActive == isRecirculationActive &&
        other.fanSpeed == fanSpeed;
  }

  @override
  int get hashCode {
    return speed.hashCode ^
        insideTemperature.hashCode ^
        outsideTemperature.hashCode ^
        range.hashCode ^
        fuelLevel.hashCode ^
        mediaVolume.hashCode ^
        isChildLockActiveLeft.hashCode ^
        isChildLockActiveRight.hashCode ^
        engineSpeed.hashCode ^
        frontLeftTire.hashCode ^
        frontRightTire.hashCode ^
        rearLeftTire.hashCode ^
        rearRightTire.hashCode ^
        isAirConditioningActive.hashCode ^
        isFrontDefrosterActive.hashCode ^
        isRearDefrosterActive.hashCode ^
        isRecirculationActive.hashCode ^
        fanSpeed.hashCode;
  }
// }
// /  class VehicleNotifier extends StateNotifier<Vehicle> {
// //    VehicleNotifier() : super(Vehicle());

// //  }
}