stack_wallet/lib/models/isar/exchange_cache/pair.dart

62 lines
1 KiB
Dart
Raw Normal View History

import 'package:isar/isar.dart';
2022-10-03 15:41:53 +00:00
part 'pair.g.dart';
2023-02-06 14:43:16 +00:00
// embedded enum // no not modify
enum SupportedRateType { fixed, estimated, both }
@collection
2022-10-02 19:37:11 +00:00
class Pair {
2023-02-06 14:43:16 +00:00
Pair({
required this.exchangeName,
required this.from,
required this.to,
required this.rateType,
});
Id? id;
@Index()
final String exchangeName;
@Index(composite: [
CompositeIndex("exchangeName"),
CompositeIndex("to"),
])
2022-10-02 19:37:11 +00:00
final String from;
final String to;
2023-02-06 14:43:16 +00:00
@enumerated
final SupportedRateType rateType;
2022-10-03 15:41:53 +00:00
Map<String, dynamic> toMap() {
2022-10-02 19:37:11 +00:00
return {
"id": id,
"exchangeName": exchangeName,
2022-10-02 19:37:11 +00:00
"from": from,
"to": to,
2023-02-06 14:43:16 +00:00
"rateType": rateType,
2022-10-02 19:37:11 +00:00
};
}
@override
2022-10-03 15:41:53 +00:00
bool operator ==(other) =>
other is Pair &&
exchangeName == other.exchangeName &&
2022-10-03 15:41:53 +00:00
from == other.from &&
to == other.to &&
2023-02-06 14:43:16 +00:00
rateType == other.rateType;
2022-10-03 15:41:53 +00:00
@override
int get hashCode => Object.hash(
exchangeName,
2022-10-03 15:41:53 +00:00
from,
to,
2023-02-06 14:43:16 +00:00
rateType,
2022-10-03 15:41:53 +00:00
);
@override
String toString() => "Pair: ${toMap()}";
2022-10-02 19:37:11 +00:00
}