186 lines
4.7 KiB
Dart
186 lines
4.7 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:hub/shared/helpers/database/database_helper.dart';
|
|
import 'package:sqflite/sqflite.dart';
|
|
|
|
enum InactiveLicenseKey {
|
|
residents,
|
|
vehicles,
|
|
openedVisits,
|
|
}
|
|
|
|
enum ActiveLicenseKey {
|
|
messages,
|
|
liberations,
|
|
reservations,
|
|
access,
|
|
orders,
|
|
completeSchedule,
|
|
providerSchedule,
|
|
deliverySchedule,
|
|
fastPass,
|
|
}
|
|
|
|
extension InactiveLicenseKeyExtension on InactiveLicenseKey {
|
|
String get value {
|
|
switch (this) {
|
|
case InactiveLicenseKey.residents:
|
|
return 'FRE-HUB-RESIDENTS';
|
|
case InactiveLicenseKey.vehicles:
|
|
return 'FRE-HUB-VEHICLES';
|
|
case InactiveLicenseKey.openedVisits:
|
|
return 'FRE-HUB-OPENED-VISITS';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
extension ActiveLicenseKeyExtension on ActiveLicenseKey {
|
|
String get value {
|
|
switch (this) {
|
|
case ActiveLicenseKey.messages:
|
|
return 'FRE-HUB-MESSAGES';
|
|
case ActiveLicenseKey.liberations:
|
|
return 'FRE-HUB-LIBERATIONS';
|
|
case ActiveLicenseKey.reservations:
|
|
return 'FRE-HUB-RESERVATIONS';
|
|
case ActiveLicenseKey.access:
|
|
return 'FRE-HUB-ACCESS';
|
|
case ActiveLicenseKey.orders:
|
|
return 'FRE-HUB-ORDERS';
|
|
case ActiveLicenseKey.completeSchedule:
|
|
return 'FRE-HUB-COMPLETE-SCHEDULE';
|
|
case ActiveLicenseKey.providerSchedule:
|
|
return 'FRE-HUB-AGE-PROV-PRESTADOR';
|
|
case ActiveLicenseKey.deliverySchedule:
|
|
return 'FRE-HUB-AGE-PROV-DELIVERY';
|
|
case ActiveLicenseKey.fastPass:
|
|
return 'FRE-HUB-FASTPASS';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
enum LicenseStorageKey {
|
|
messages,
|
|
liberations,
|
|
reservations,
|
|
access,
|
|
openedVisits,
|
|
vehicles,
|
|
residents,
|
|
pets,
|
|
orders,
|
|
completeSchedule,
|
|
providerSchedule,
|
|
deliverySchedule,
|
|
fastPass,
|
|
}
|
|
|
|
extension LicenseKeyExtension on LicenseStorageKey {
|
|
String get value {
|
|
switch (this) {
|
|
case LicenseStorageKey.messages:
|
|
return 'FRE-HUB-MESSAGES';
|
|
case LicenseStorageKey.liberations:
|
|
return 'FRE-HUB-LIBERATIONS';
|
|
case LicenseStorageKey.reservations:
|
|
return 'FRE-HUB-RESERVATIONS';
|
|
case LicenseStorageKey.access:
|
|
return 'FRE-HUB-ACCESS';
|
|
case LicenseStorageKey.openedVisits:
|
|
return 'FRE-HUB-OPENED-VISITS';
|
|
case LicenseStorageKey.vehicles:
|
|
return 'FRE-HUB-VEHICLES';
|
|
case LicenseStorageKey.residents:
|
|
return 'FRE-HUB-RESIDENTS';
|
|
case LicenseStorageKey.pets:
|
|
return 'FRE-HUB-PETS';
|
|
case LicenseStorageKey.orders:
|
|
return 'FRE-HUB-ORDERS';
|
|
case LicenseStorageKey.completeSchedule:
|
|
return 'FRE-HUB-COMPLETE-SCHEDULE';
|
|
case LicenseStorageKey.providerSchedule:
|
|
return 'FRE-HUB-AGE-PROV-PRESTADOR';
|
|
case LicenseStorageKey.deliverySchedule:
|
|
return 'FRE-HUB-AGE-PROV-DELIVERY';
|
|
case LicenseStorageKey.fastPass:
|
|
return 'FRE-HUB-FASTPASS';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
class LicenseHelper {
|
|
LicenseHelper._();
|
|
|
|
static final LicenseHelper instance = LicenseHelper._();
|
|
|
|
static const String tableLicense = 'license';
|
|
|
|
static String get createTableQuery => '''
|
|
CREATE TABLE $tableLicense (
|
|
key TEXT UNIQUE,
|
|
display TEXT,
|
|
expirationDate TEXT,
|
|
startDate TEXT,
|
|
quantity TEXT
|
|
);
|
|
''';
|
|
|
|
Future<void> init() async {
|
|
await DatabaseStorage.instance.init();
|
|
}
|
|
|
|
static Future<void> insertLicenseFoo(final List<String> key, final String display) async {
|
|
for (var element in key) {
|
|
DatabaseStorage.database.insert(
|
|
tableLicense,
|
|
{
|
|
'key': element,
|
|
'display': display,
|
|
'expirationDate': '',
|
|
'startDate': '',
|
|
'quantity': '',
|
|
},
|
|
conflictAlgorithm: ConflictAlgorithm.ignore,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<String?> g(String key) async {
|
|
var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]);
|
|
if (response.isEmpty) {
|
|
return null;
|
|
}
|
|
return response.first['value'].toString();
|
|
}
|
|
|
|
Future<void> s<T>(String key, T value) async {
|
|
log('setLicense($key, $value)');
|
|
value as Map<String, dynamic>;
|
|
|
|
await DatabaseStorage.database.insert(
|
|
tableLicense,
|
|
{
|
|
'key': key,
|
|
'display': value['display'],
|
|
'expirationDate': value['expirationDate'],
|
|
'startDate': value['startDate'],
|
|
'quantity': value['quantity'],
|
|
},
|
|
conflictAlgorithm: ConflictAlgorithm.replace);
|
|
}
|
|
|
|
Future<void> d(String key) async {
|
|
await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]);
|
|
}
|
|
|
|
Future<void> c() async {
|
|
await DatabaseStorage.database.delete(tableLicense);
|
|
}
|
|
}
|