Created
December 15, 2023 03:07
-
-
Save brasizza/71251cf3488bc00a7f3f3fec32f5af50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:convert'; | |
| import 'package:epocpdv/src/core/extensions/strings_extension.dart'; | |
| import 'package:epocpdv/src/core/helpers/utils.dart'; | |
| import 'package:isar/isar.dart'; | |
| part 'ativacao_model.g.dart'; | |
| @Name('ativacao') | |
| @Collection() | |
| class ActivationModel { | |
| static String get tableName => 'ativacao'; | |
| final int id; | |
| final String metodo; | |
| final String hashemp; | |
| final String nomeEmpresa; | |
| final String? url; | |
| final String codHost; | |
| final String cnpj; | |
| ActivationModel({ | |
| required this.id, | |
| required this.metodo, | |
| required this.hashemp, | |
| required this.nomeEmpresa, | |
| this.url = '', | |
| required this.codHost, | |
| required this.cnpj, | |
| }); | |
| ActivationModel copyWith({ | |
| String? metodo, | |
| String? hashemp, | |
| String? nomeEmpresa, | |
| String? url, | |
| String? codHost, | |
| String? cnpj, | |
| }) { | |
| return ActivationModel( | |
| id: 0, | |
| metodo: metodo ?? this.metodo, | |
| hashemp: hashemp ?? this.hashemp, | |
| nomeEmpresa: nomeEmpresa ?? this.nomeEmpresa, | |
| url: url ?? this.url, | |
| codHost: codHost ?? this.codHost, | |
| cnpj: cnpj ?? this.cnpj, | |
| ); | |
| } | |
| Map<String, dynamic> toMap() { | |
| return <String, dynamic>{ | |
| 'metodo': metodo, | |
| 'hashemp': hashemp, | |
| 'nomeEmpresa': nomeEmpresa, | |
| 'url': url, | |
| 'codHost': codHost, | |
| 'cnpj': cnpj, | |
| }; | |
| } | |
| factory ActivationModel.fromMap(Map<String, dynamic> map) { | |
| return ActivationModel( | |
| id: 0, | |
| metodo: map['metodo'] as String, | |
| hashemp: map['hashemp'] as String, | |
| nomeEmpresa: map['nomeEmpresa'] as String, | |
| url: map['url'] != null ? map['url'] as String : null, | |
| codHost: (map['codHost'] as String).fromBase64, | |
| cnpj: map['cnpj'] as String, | |
| ); | |
| } | |
| factory ActivationModel.fromStringQrcode(String qrcode) { | |
| final map = qrcode.split('|'); | |
| return ActivationModel( | |
| id: 0, | |
| metodo: 'QRCODE', | |
| hashemp: (map[0]), | |
| nomeEmpresa: map[1], | |
| url: map[2], | |
| codHost: (Utils.base64ToStringBig(map[3])), | |
| cnpj: (map[4]), | |
| ); | |
| } | |
| String toJson() => json.encode(toMap()); | |
| factory ActivationModel.fromJson(String source) => | |
| ActivationModel.fromMap(json.decode(source) as Map<String, dynamic>); | |
| @override | |
| String toString() { | |
| return 'ActivationModel(metodo: $metodo, hashemp: $hashemp, nomeEmpresa: $nomeEmpresa, url: $url, codHost: $codHost, cnpj: $cnpj)'; | |
| } | |
| @override | |
| bool operator ==(Object other) { | |
| if (identical(this, other)) return true; | |
| return other is ActivationModel && | |
| other.metodo == metodo && | |
| other.hashemp == hashemp && | |
| other.nomeEmpresa == nomeEmpresa && | |
| other.url == url && | |
| other.codHost == codHost && | |
| other.cnpj == cnpj; | |
| } | |
| @override | |
| int get hashCode { | |
| return metodo.hashCode ^ | |
| hashemp.hashCode ^ | |
| nomeEmpresa.hashCode ^ | |
| url.hashCode ^ | |
| codHost.hashCode ^ | |
| cnpj.hashCode; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment