diff --git a/.claude/commands/prepare-release.md b/.claude/commands/prepare-release.md new file mode 100644 index 00000000..873a211d --- /dev/null +++ b/.claude/commands/prepare-release.md @@ -0,0 +1,80 @@ +# Prepare a release + +Bump the version, document the changelog, and open a PR from `development` to `main`. + +## Usage + +``` +/prepare-release +``` + +Where `` is the new semver string (e.g. `3.6.21`). + +## Steps + +### 1. Validate inputs + +- Confirm the working directory is clean (`git status`). If there are uncommitted changes, stop + and tell the user to commit or stash them first. +- Confirm the current branch is `development`. If not, stop and warn the user. +- Confirm `` is a valid semver string (e.g. `3.6.21`, `4.0.0`). + +### 2. Collect changes since last release + +Run: +``` +git log --oneline ..HEAD +``` +or if tags are not present, compare with `main`: +``` +git log --oneline main..HEAD +``` +Read the commit messages to understand what changed. Ignore pure chore/refactor commits +(e.g. CLAUDE.md updates, code generation runs) unless they are meaningful to library consumers. +Focus on: new models, new fields, removed/deprecated fields, bug fixes, behaviour changes. + +### 3. Update `pubspec.yaml` + +Edit the `version:` line: +```yaml +version: "" +``` + +### 4. Prepend entry to `CHANGELOG.md` + +Insert a new section at the top (after the `# Changelog` heading) following the existing style: +```markdown +## + +- +- +``` + +Rules: +- One bullet per logical change (not per commit). +- Mention model names, field names, and enum values using backticks. +- Keep bullets concise — one sentence each. +- Do not include internal/tooling changes (CLAUDE.md, skill files, code generation, etc.). + +### 5. Commit the release + +Stage only `pubspec.yaml` and `CHANGELOG.md`, then commit: +``` +git add pubspec.yaml CHANGELOG.md +git commit -m "chore: bump version to and update changelog" +``` + +### 6. Push and open PR + +``` +git push origin development +``` + +Then create a PR from `development` → `main` using `gh pr create`: +- Title: `chore: release ` +- Body: the changelog entry you just wrote (the bullet list only, no heading) +- Do NOT include a Test plan section (per project rules) + +### 7. Report + +Print the PR URL so the user can review and merge it. diff --git a/.claude/commands/to-library.md b/.claude/commands/to-library.md new file mode 100644 index 00000000..4664efb6 --- /dev/null +++ b/.claude/commands/to-library.md @@ -0,0 +1,77 @@ +# Convert flat model file to library module + +Convert a flat `lib/src/.dart` file (currently a `part of` the root library) into a +self-contained sub-library with the `library` / `part` / `part of` pattern used across this +codebase. + +## Usage + +``` +/to-library +``` + +Where `` is the module name (e.g. `access`, `algorithm`, `tag`). +The flat source file must exist at `lib/src/.dart`. + +## What this skill does + +1. **Read** `lib/src/.dart` — understand every top-level declaration (classes, enums, + mixins, extensions, typedefs). + +2. **Decide how to split** — one source file per logical unit inside `lib/src//src/`. + Typical split: one file per class/enum, or group tightly-coupled helpers together. + Follow existing modules as reference (e.g. `lib/src/access/`, `lib/src/ats/`). + +3. **Create the module library** `lib/src//.dart`: + ```dart + library; + + import 'package:collection/collection.dart'; // only if needed + import 'package:freezed_annotation/freezed_annotation.dart'; // only if needed + import 'package:layrz_models/layrz_models.dart'; // only if needed + + part '.freezed.dart'; // only if @freezed/@unfreezed classes exist + part '.g.dart'; // only if fromJson exists + + part 'src/foo.dart'; + part 'src/bar.dart'; + // ... + ``` + Include only the imports actually needed. + +4. **Create each source file** under `lib/src//src/.dart`: + ```dart + part of '../.dart'; + + // original content of that declaration + ``` + +5. **Update `lib/layrz_models.dart`**: + - Remove `part 'src/.dart';` + - Add before the `part 'layrz_models.freezed.dart';` line: + ```dart + import 'src//.dart'; // only if types from this module are used + export 'src//.dart'; // in other part files of layrz_models.dart + ``` + Use `// import ...` (commented-out) + `export` if NOT used in part files. + + **Import vs export-only rule**: grep the other `lib/src/*.dart` part files for any + type name from this module. If any part file in `layrz_models.dart` references a type, + the library needs `import` (not just `export`) so the type is in scope for those parts. + +6. **Delete** `lib/src/.dart`. + +7. **Run code generation**: `dart run build_runner build --delete-conflicting-outputs` + +8. **Report** what was created and whether the build succeeded. + +## Rules + +- Never manually edit `.freezed.dart` or `.g.dart` files. +- Keep `part of` paths relative: `part of '../.dart';` +- All `part` declarations in the library file must precede no `import`/`export` — but + `library;` comes first, then imports, then `part` directives. +- Export directives in `layrz_models.dart` must precede `part` directives — place the new + export/import block before `part 'layrz_models.freezed.dart';`. +- Follow existing dartdoc comment style (all classes and fields documented). +- Do not add features or refactor beyond the mechanical conversion. diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies deleted file mode 100644 index 95a5f300..00000000 --- a/.flutter-plugins-dependencies +++ /dev/null @@ -1 +0,0 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"file_picker","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-10.3.3\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[],"dev_dependency":false},{"name":"permission_handler_apple","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_apple-9.4.7\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"pointer_interceptor_ios","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\pointer_interceptor_ios-0.10.1\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"shared_preferences_foundation","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.5.4\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[],"dev_dependency":false},{"name":"sqlite3_flutter_libs","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqlite3_flutter_libs-0.5.40\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[],"dev_dependency":false},{"name":"url_launcher_ios","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\url_launcher_ios-6.3.4\\\\","native_build":true,"dependencies":[],"dev_dependency":false}],"android":[{"name":"file_picker","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-10.3.3\\\\","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"],"dev_dependency":false},{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_plugin_android_lifecycle-2.0.30\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"path_provider_android","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.18\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"permission_handler_android","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_android-13.0.1\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"shared_preferences_android","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_android-2.4.14\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"sqlite3_flutter_libs","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqlite3_flutter_libs-0.5.40\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"url_launcher_android","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\url_launcher_android-6.3.23\\\\","native_build":true,"dependencies":[],"dev_dependency":false}],"macos":[{"name":"file_picker","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-10.3.3\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[],"dev_dependency":false},{"name":"shared_preferences_foundation","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.5.4\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[],"dev_dependency":false},{"name":"sqlite3_flutter_libs","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqlite3_flutter_libs-0.5.40\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[],"dev_dependency":false},{"name":"url_launcher_macos","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\url_launcher_macos-3.2.3\\\\","native_build":true,"dependencies":[],"dev_dependency":false}],"linux":[{"name":"file_picker","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-10.3.3\\\\","native_build":false,"dependencies":[],"dev_dependency":false},{"name":"path_provider_linux","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[],"dev_dependency":false},{"name":"shared_preferences_linux","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_linux-2.4.1\\\\","native_build":false,"dependencies":["path_provider_linux"],"dev_dependency":false},{"name":"sqlite3_flutter_libs","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqlite3_flutter_libs-0.5.40\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"url_launcher_linux","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\url_launcher_linux-3.2.1\\\\","native_build":true,"dependencies":[],"dev_dependency":false}],"windows":[{"name":"file_picker","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-10.3.3\\\\","native_build":false,"dependencies":[],"dev_dependency":false},{"name":"path_provider_windows","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.3.0\\\\","native_build":false,"dependencies":[],"dev_dependency":false},{"name":"permission_handler_windows","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_windows-0.2.1\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"shared_preferences_windows","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_windows-2.4.1\\\\","native_build":false,"dependencies":["path_provider_windows"],"dev_dependency":false},{"name":"sqlite3_flutter_libs","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqlite3_flutter_libs-0.5.40\\\\","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"url_launcher_windows","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\url_launcher_windows-3.1.4\\\\","native_build":true,"dependencies":[],"dev_dependency":false}],"web":[{"name":"file_picker","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-10.3.3\\\\","dependencies":[],"dev_dependency":false},{"name":"permission_handler_html","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_html-0.1.3+5\\\\","dependencies":[],"dev_dependency":false},{"name":"pointer_interceptor_web","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\pointer_interceptor_web-0.10.3\\\\","dependencies":[],"dev_dependency":false},{"name":"shared_preferences_web","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_web-2.4.3\\\\","dependencies":[],"dev_dependency":false},{"name":"url_launcher_web","path":"C:\\\\Users\\\\luisr\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\url_launcher_web-2.4.1\\\\","dependencies":[],"dev_dependency":false}]},"dependencyGraph":[{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_html","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_html","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]},{"name":"pointer_interceptor","dependencies":["pointer_interceptor_ios","pointer_interceptor_web"]},{"name":"pointer_interceptor_ios","dependencies":[]},{"name":"pointer_interceptor_web","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"sqlite3_flutter_libs","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_android","url_launcher_ios","url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_android","dependencies":[]},{"name":"url_launcher_ios","dependencies":[]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2026-03-18 23:52:24.881691","version":"3.41.4","swift_package_manager_enabled":{"ios":false,"macos":false}} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 57dad8c7..b1ed596e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,8 @@ # Flutter/Dart/Pub related # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +.flutter-plugins +.flutter-plugins-dependencies /pubspec.lock **/doc/api/ .dart_tool/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eda4343..bb39ae33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 3.6.21 + +- Added `PoiInput` model to the `map` module with `save()` support for creating and editing points of interest via GraphQL. +- Added `PoiApiResponse` helper class to the `map` module. + ## 3.6.20 - Added `hasWorldwideCoverage` to `Device` model to represent if the device has worldwide coverage, for the BHS use case, this field is used to identify if the device has GPS insurance. - Added `hasGpsInsurance` to `User` model to represent if the user has GPS insurance, for the BHS use case. diff --git a/CLAUDE.md b/CLAUDE.md index 15c78a75..4219f2d2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -146,3 +146,8 @@ Each test file typically tests: - Follow existing documentation patterns - all models and fields should have dartdoc comments - Use nullable fields (`String?`) liberally as API responses may have missing data - Deprecation: Use `@Deprecated("migration message")` for fields being phased out + +## Other considerations + +- "wrap it up" - Means review the changes, commit and push, and create a pull request if the user wants +- Do not include Test plan on the PR body under any circumstances, the code should be tested before the PR. diff --git a/lib/layrz_models.dart b/lib/layrz_models.dart index 63a9c226..e364e659 100644 --- a/lib/layrz_models.dart +++ b/lib/layrz_models.dart @@ -143,11 +143,13 @@ export 'src/token/token.dart'; // import 'src/permissions/permissions.dart'; export 'src/permissions/permissions.dart'; +import 'src/access/access.dart'; +export 'src/access/access.dart'; + part 'layrz_models.freezed.dart'; part 'layrz_models.g.dart'; /// Models that should be re-organized to sub-modules -part 'src/access.dart'; part 'src/accessibility/shortcut.dart'; part 'src/algorithm.dart'; part 'src/billing_plan.dart'; diff --git a/lib/layrz_models.freezed.dart b/lib/layrz_models.freezed.dart index cfa0b1ee..bc743605 100644 --- a/lib/layrz_models.freezed.dart +++ b/lib/layrz_models.freezed.dart @@ -12,605 +12,6 @@ part of 'layrz_models.dart'; // dart format off T _$identity(T value) => value; -/// @nodoc -mixin _$Access { - - String get id; String? get label; bool? get read; bool? get write; bool? get manage; String? get objectId; String get userId; User? get user;@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule get module; -/// Create a copy of Access -/// with the given fields replaced by the non-null parameter values. -@JsonKey(includeFromJson: false, includeToJson: false) -@pragma('vm:prefer-inline') -$AccessCopyWith get copyWith => _$AccessCopyWithImpl(this as Access, _$identity); - - /// Serializes this Access to a JSON map. - Map toJson(); - - -@override -bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is Access&&(identical(other.id, id) || other.id == id)&&(identical(other.label, label) || other.label == label)&&(identical(other.read, read) || other.read == read)&&(identical(other.write, write) || other.write == write)&&(identical(other.manage, manage) || other.manage == manage)&&(identical(other.objectId, objectId) || other.objectId == objectId)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.user, user) || other.user == user)&&(identical(other.module, module) || other.module == module)); -} - -@JsonKey(includeFromJson: false, includeToJson: false) -@override -int get hashCode => Object.hash(runtimeType,id,label,read,write,manage,objectId,userId,user,module); - -@override -String toString() { - return 'Access(id: $id, label: $label, read: $read, write: $write, manage: $manage, objectId: $objectId, userId: $userId, user: $user, module: $module)'; -} - - -} - -/// @nodoc -abstract mixin class $AccessCopyWith<$Res> { - factory $AccessCopyWith(Access value, $Res Function(Access) _then) = _$AccessCopyWithImpl; -@useResult -$Res call({ - String id, String? label, bool? read, bool? write, bool? manage, String? objectId, String userId, User? user,@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module -}); - - -$UserCopyWith<$Res>? get user; - -} -/// @nodoc -class _$AccessCopyWithImpl<$Res> - implements $AccessCopyWith<$Res> { - _$AccessCopyWithImpl(this._self, this._then); - - final Access _self; - final $Res Function(Access) _then; - -/// Create a copy of Access -/// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? label = freezed,Object? read = freezed,Object? write = freezed,Object? manage = freezed,Object? objectId = freezed,Object? userId = null,Object? user = freezed,Object? module = null,}) { - return _then(_self.copyWith( -id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable -as String,label: freezed == label ? _self.label : label // ignore: cast_nullable_to_non_nullable -as String?,read: freezed == read ? _self.read : read // ignore: cast_nullable_to_non_nullable -as bool?,write: freezed == write ? _self.write : write // ignore: cast_nullable_to_non_nullable -as bool?,manage: freezed == manage ? _self.manage : manage // ignore: cast_nullable_to_non_nullable -as bool?,objectId: freezed == objectId ? _self.objectId : objectId // ignore: cast_nullable_to_non_nullable -as String?,userId: null == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable -as String,user: freezed == user ? _self.user : user // ignore: cast_nullable_to_non_nullable -as User?,module: null == module ? _self.module : module // ignore: cast_nullable_to_non_nullable -as AccessModule, - )); -} -/// Create a copy of Access -/// with the given fields replaced by the non-null parameter values. -@override -@pragma('vm:prefer-inline') -$UserCopyWith<$Res>? get user { - if (_self.user == null) { - return null; - } - - return $UserCopyWith<$Res>(_self.user!, (value) { - return _then(_self.copyWith(user: value)); - }); -} -} - - -/// Adds pattern-matching-related methods to [Access]. -extension AccessPatterns on Access { -/// A variant of `map` that fallback to returning `orElse`. -/// -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case final Subclass value: -/// return ...; -/// case _: -/// return orElse(); -/// } -/// ``` - -@optionalTypeArgs TResult maybeMap(TResult Function( _Access value)? $default,{required TResult orElse(),}){ -final _that = this; -switch (_that) { -case _Access() when $default != null: -return $default(_that);case _: - return orElse(); - -} -} -/// A `switch`-like method, using callbacks. -/// -/// Callbacks receives the raw object, upcasted. -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case final Subclass value: -/// return ...; -/// case final Subclass2 value: -/// return ...; -/// } -/// ``` - -@optionalTypeArgs TResult map(TResult Function( _Access value) $default,){ -final _that = this; -switch (_that) { -case _Access(): -return $default(_that);case _: - throw StateError('Unexpected subclass'); - -} -} -/// A variant of `map` that fallback to returning `null`. -/// -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case final Subclass value: -/// return ...; -/// case _: -/// return null; -/// } -/// ``` - -@optionalTypeArgs TResult? mapOrNull(TResult? Function( _Access value)? $default,){ -final _that = this; -switch (_that) { -case _Access() when $default != null: -return $default(_that);case _: - return null; - -} -} -/// A variant of `when` that fallback to an `orElse` callback. -/// -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case Subclass(:final field): -/// return ...; -/// case _: -/// return orElse(); -/// } -/// ``` - -@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String? label, bool? read, bool? write, bool? manage, String? objectId, String userId, User? user, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module)? $default,{required TResult orElse(),}) {final _that = this; -switch (_that) { -case _Access() when $default != null: -return $default(_that.id,_that.label,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.user,_that.module);case _: - return orElse(); - -} -} -/// A `switch`-like method, using callbacks. -/// -/// As opposed to `map`, this offers destructuring. -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case Subclass(:final field): -/// return ...; -/// case Subclass2(:final field2): -/// return ...; -/// } -/// ``` - -@optionalTypeArgs TResult when(TResult Function( String id, String? label, bool? read, bool? write, bool? manage, String? objectId, String userId, User? user, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module) $default,) {final _that = this; -switch (_that) { -case _Access(): -return $default(_that.id,_that.label,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.user,_that.module);case _: - throw StateError('Unexpected subclass'); - -} -} -/// A variant of `when` that fallback to returning `null` -/// -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case Subclass(:final field): -/// return ...; -/// case _: -/// return null; -/// } -/// ``` - -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String? label, bool? read, bool? write, bool? manage, String? objectId, String userId, User? user, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module)? $default,) {final _that = this; -switch (_that) { -case _Access() when $default != null: -return $default(_that.id,_that.label,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.user,_that.module);case _: - return null; - -} -} - -} - -/// @nodoc -@JsonSerializable() - -class _Access implements Access { - const _Access({required this.id, this.label, this.read, this.write, this.manage, this.objectId, required this.userId, this.user, @JsonKey(unknownEnumValue: AccessModule.unknown) required this.module}); - factory _Access.fromJson(Map json) => _$AccessFromJson(json); - -@override final String id; -@override final String? label; -@override final bool? read; -@override final bool? write; -@override final bool? manage; -@override final String? objectId; -@override final String userId; -@override final User? user; -@override@JsonKey(unknownEnumValue: AccessModule.unknown) final AccessModule module; - -/// Create a copy of Access -/// with the given fields replaced by the non-null parameter values. -@override @JsonKey(includeFromJson: false, includeToJson: false) -@pragma('vm:prefer-inline') -_$AccessCopyWith<_Access> get copyWith => __$AccessCopyWithImpl<_Access>(this, _$identity); - -@override -Map toJson() { - return _$AccessToJson(this, ); -} - -@override -bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _Access&&(identical(other.id, id) || other.id == id)&&(identical(other.label, label) || other.label == label)&&(identical(other.read, read) || other.read == read)&&(identical(other.write, write) || other.write == write)&&(identical(other.manage, manage) || other.manage == manage)&&(identical(other.objectId, objectId) || other.objectId == objectId)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.user, user) || other.user == user)&&(identical(other.module, module) || other.module == module)); -} - -@JsonKey(includeFromJson: false, includeToJson: false) -@override -int get hashCode => Object.hash(runtimeType,id,label,read,write,manage,objectId,userId,user,module); - -@override -String toString() { - return 'Access(id: $id, label: $label, read: $read, write: $write, manage: $manage, objectId: $objectId, userId: $userId, user: $user, module: $module)'; -} - - -} - -/// @nodoc -abstract mixin class _$AccessCopyWith<$Res> implements $AccessCopyWith<$Res> { - factory _$AccessCopyWith(_Access value, $Res Function(_Access) _then) = __$AccessCopyWithImpl; -@override @useResult -$Res call({ - String id, String? label, bool? read, bool? write, bool? manage, String? objectId, String userId, User? user,@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module -}); - - -@override $UserCopyWith<$Res>? get user; - -} -/// @nodoc -class __$AccessCopyWithImpl<$Res> - implements _$AccessCopyWith<$Res> { - __$AccessCopyWithImpl(this._self, this._then); - - final _Access _self; - final $Res Function(_Access) _then; - -/// Create a copy of Access -/// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? label = freezed,Object? read = freezed,Object? write = freezed,Object? manage = freezed,Object? objectId = freezed,Object? userId = null,Object? user = freezed,Object? module = null,}) { - return _then(_Access( -id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable -as String,label: freezed == label ? _self.label : label // ignore: cast_nullable_to_non_nullable -as String?,read: freezed == read ? _self.read : read // ignore: cast_nullable_to_non_nullable -as bool?,write: freezed == write ? _self.write : write // ignore: cast_nullable_to_non_nullable -as bool?,manage: freezed == manage ? _self.manage : manage // ignore: cast_nullable_to_non_nullable -as bool?,objectId: freezed == objectId ? _self.objectId : objectId // ignore: cast_nullable_to_non_nullable -as String?,userId: null == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable -as String,user: freezed == user ? _self.user : user // ignore: cast_nullable_to_non_nullable -as User?,module: null == module ? _self.module : module // ignore: cast_nullable_to_non_nullable -as AccessModule, - )); -} - -/// Create a copy of Access -/// with the given fields replaced by the non-null parameter values. -@override -@pragma('vm:prefer-inline') -$UserCopyWith<$Res>? get user { - if (_self.user == null) { - return null; - } - - return $UserCopyWith<$Res>(_self.user!, (value) { - return _then(_self.copyWith(user: value)); - }); -} -} - - -/// @nodoc -mixin _$AccessInput { - -/// Represents the id of the access. - String? get id;/// Represents the id of the access. - set id(String? value);/// Represents the read permission. - bool get read;/// Represents the read permission. - set read(bool value);/// Represents the write permission. - bool get write;/// Represents the write permission. - set write(bool value);/// Represents the manage permission. - bool get manage;/// Represents the manage permission. - set manage(bool value);/// Represents the id of the object. - String? get objectId;/// Represents the id of the object. - set objectId(String? value);/// Represents the id of the user. - String? get userId;/// Represents the id of the user. - set userId(String? value);/// Represents the module of the access. -@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule get module;/// Represents the module of the access. -@JsonKey(unknownEnumValue: AccessModule.unknown) set module(AccessModule value); -/// Create a copy of AccessInput -/// with the given fields replaced by the non-null parameter values. -@JsonKey(includeFromJson: false, includeToJson: false) -@pragma('vm:prefer-inline') -$AccessInputCopyWith get copyWith => _$AccessInputCopyWithImpl(this as AccessInput, _$identity); - - /// Serializes this AccessInput to a JSON map. - Map toJson(); - - - - -@override -String toString() { - return 'AccessInput(id: $id, read: $read, write: $write, manage: $manage, objectId: $objectId, userId: $userId, module: $module)'; -} - - -} - -/// @nodoc -abstract mixin class $AccessInputCopyWith<$Res> { - factory $AccessInputCopyWith(AccessInput value, $Res Function(AccessInput) _then) = _$AccessInputCopyWithImpl; -@useResult -$Res call({ - String? id, bool read, bool write, bool manage, String? objectId, String? userId,@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module -}); - - - - -} -/// @nodoc -class _$AccessInputCopyWithImpl<$Res> - implements $AccessInputCopyWith<$Res> { - _$AccessInputCopyWithImpl(this._self, this._then); - - final AccessInput _self; - final $Res Function(AccessInput) _then; - -/// Create a copy of AccessInput -/// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? id = freezed,Object? read = null,Object? write = null,Object? manage = null,Object? objectId = freezed,Object? userId = freezed,Object? module = null,}) { - return _then(_self.copyWith( -id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable -as String?,read: null == read ? _self.read : read // ignore: cast_nullable_to_non_nullable -as bool,write: null == write ? _self.write : write // ignore: cast_nullable_to_non_nullable -as bool,manage: null == manage ? _self.manage : manage // ignore: cast_nullable_to_non_nullable -as bool,objectId: freezed == objectId ? _self.objectId : objectId // ignore: cast_nullable_to_non_nullable -as String?,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable -as String?,module: null == module ? _self.module : module // ignore: cast_nullable_to_non_nullable -as AccessModule, - )); -} - -} - - -/// Adds pattern-matching-related methods to [AccessInput]. -extension AccessInputPatterns on AccessInput { -/// A variant of `map` that fallback to returning `orElse`. -/// -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case final Subclass value: -/// return ...; -/// case _: -/// return orElse(); -/// } -/// ``` - -@optionalTypeArgs TResult maybeMap(TResult Function( _AccessInput value)? $default,{required TResult orElse(),}){ -final _that = this; -switch (_that) { -case _AccessInput() when $default != null: -return $default(_that);case _: - return orElse(); - -} -} -/// A `switch`-like method, using callbacks. -/// -/// Callbacks receives the raw object, upcasted. -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case final Subclass value: -/// return ...; -/// case final Subclass2 value: -/// return ...; -/// } -/// ``` - -@optionalTypeArgs TResult map(TResult Function( _AccessInput value) $default,){ -final _that = this; -switch (_that) { -case _AccessInput(): -return $default(_that);case _: - throw StateError('Unexpected subclass'); - -} -} -/// A variant of `map` that fallback to returning `null`. -/// -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case final Subclass value: -/// return ...; -/// case _: -/// return null; -/// } -/// ``` - -@optionalTypeArgs TResult? mapOrNull(TResult? Function( _AccessInput value)? $default,){ -final _that = this; -switch (_that) { -case _AccessInput() when $default != null: -return $default(_that);case _: - return null; - -} -} -/// A variant of `when` that fallback to an `orElse` callback. -/// -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case Subclass(:final field): -/// return ...; -/// case _: -/// return orElse(); -/// } -/// ``` - -@optionalTypeArgs TResult maybeWhen(TResult Function( String? id, bool read, bool write, bool manage, String? objectId, String? userId, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module)? $default,{required TResult orElse(),}) {final _that = this; -switch (_that) { -case _AccessInput() when $default != null: -return $default(_that.id,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.module);case _: - return orElse(); - -} -} -/// A `switch`-like method, using callbacks. -/// -/// As opposed to `map`, this offers destructuring. -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case Subclass(:final field): -/// return ...; -/// case Subclass2(:final field2): -/// return ...; -/// } -/// ``` - -@optionalTypeArgs TResult when(TResult Function( String? id, bool read, bool write, bool manage, String? objectId, String? userId, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module) $default,) {final _that = this; -switch (_that) { -case _AccessInput(): -return $default(_that.id,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.module);case _: - throw StateError('Unexpected subclass'); - -} -} -/// A variant of `when` that fallback to returning `null` -/// -/// It is equivalent to doing: -/// ```dart -/// switch (sealedClass) { -/// case Subclass(:final field): -/// return ...; -/// case _: -/// return null; -/// } -/// ``` - -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String? id, bool read, bool write, bool manage, String? objectId, String? userId, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module)? $default,) {final _that = this; -switch (_that) { -case _AccessInput() when $default != null: -return $default(_that.id,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.module);case _: - return null; - -} -} - -} - -/// @nodoc -@JsonSerializable() - -class _AccessInput implements AccessInput { - _AccessInput({this.id, this.read = false, this.write = false, this.manage = false, this.objectId, this.userId, @JsonKey(unknownEnumValue: AccessModule.unknown) required this.module}); - factory _AccessInput.fromJson(Map json) => _$AccessInputFromJson(json); - -/// Represents the id of the access. -@override String? id; -/// Represents the read permission. -@override@JsonKey() bool read; -/// Represents the write permission. -@override@JsonKey() bool write; -/// Represents the manage permission. -@override@JsonKey() bool manage; -/// Represents the id of the object. -@override String? objectId; -/// Represents the id of the user. -@override String? userId; -/// Represents the module of the access. -@override@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module; - -/// Create a copy of AccessInput -/// with the given fields replaced by the non-null parameter values. -@override @JsonKey(includeFromJson: false, includeToJson: false) -@pragma('vm:prefer-inline') -_$AccessInputCopyWith<_AccessInput> get copyWith => __$AccessInputCopyWithImpl<_AccessInput>(this, _$identity); - -@override -Map toJson() { - return _$AccessInputToJson(this, ); -} - - - -@override -String toString() { - return 'AccessInput(id: $id, read: $read, write: $write, manage: $manage, objectId: $objectId, userId: $userId, module: $module)'; -} - - -} - -/// @nodoc -abstract mixin class _$AccessInputCopyWith<$Res> implements $AccessInputCopyWith<$Res> { - factory _$AccessInputCopyWith(_AccessInput value, $Res Function(_AccessInput) _then) = __$AccessInputCopyWithImpl; -@override @useResult -$Res call({ - String? id, bool read, bool write, bool manage, String? objectId, String? userId,@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module -}); - - - - -} -/// @nodoc -class __$AccessInputCopyWithImpl<$Res> - implements _$AccessInputCopyWith<$Res> { - __$AccessInputCopyWithImpl(this._self, this._then); - - final _AccessInput _self; - final $Res Function(_AccessInput) _then; - -/// Create a copy of AccessInput -/// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? id = freezed,Object? read = null,Object? write = null,Object? manage = null,Object? objectId = freezed,Object? userId = freezed,Object? module = null,}) { - return _then(_AccessInput( -id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable -as String?,read: null == read ? _self.read : read // ignore: cast_nullable_to_non_nullable -as bool,write: null == write ? _self.write : write // ignore: cast_nullable_to_non_nullable -as bool,manage: null == manage ? _self.manage : manage // ignore: cast_nullable_to_non_nullable -as bool,objectId: freezed == objectId ? _self.objectId : objectId // ignore: cast_nullable_to_non_nullable -as String?,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable -as String?,module: null == module ? _self.module : module // ignore: cast_nullable_to_non_nullable -as AccessModule, - )); -} - - -} - - /// @nodoc mixin _$LinkShortcut { diff --git a/lib/layrz_models.g.dart b/lib/layrz_models.g.dart index de478e74..35ce4663 100644 --- a/lib/layrz_models.g.dart +++ b/lib/layrz_models.g.dart @@ -6,98 +6,6 @@ part of 'layrz_models.dart'; // JsonSerializableGenerator // ************************************************************************** -_Access _$AccessFromJson(Map json) => _Access( - id: json['id'] as String, - label: json['label'] as String?, - read: json['read'] as bool?, - write: json['write'] as bool?, - manage: json['manage'] as bool?, - objectId: json['objectId'] as String?, - userId: json['userId'] as String, - user: json['user'] == null - ? null - : User.fromJson(json['user'] as Map), - module: $enumDecode( - _$AccessModuleEnumMap, - json['module'], - unknownValue: AccessModule.unknown, - ), -); - -Map _$AccessToJson(_Access instance) => { - 'id': instance.id, - 'label': instance.label, - 'read': instance.read, - 'write': instance.write, - 'manage': instance.manage, - 'objectId': instance.objectId, - 'userId': instance.userId, - 'user': instance.user?.toJson(), - 'module': instance.module.toJson(), -}; - -const _$AccessModuleEnumMap = { - AccessModule.actions: 'ACTIONS', - AccessModule.assets: 'ASSETS', - AccessModule.careprotocols: 'CAREPROTOCOLS', - AccessModule.checkpoints: 'CHECKPOINTS', - AccessModule.conciergeForms: 'CONCIERGE_FORMS', - AccessModule.coreprocess: 'COREPROCESS', - AccessModule.devices: 'DEVICES', - AccessModule.functions: 'FUNCTIONS', - AccessModule.geofences: 'GEOFENCES', - AccessModule.inboundServices: 'INBOUND_SERVICES', - AccessModule.operations: 'OPERATIONS', - AccessModule.outboundServices: 'OUTBOUND_SERVICES', - AccessModule.presets: 'PRESETS', - AccessModule.references: 'REFERENCES', - AccessModule.externalAccounts: 'EXTERNAL_ACCOUNTS', - AccessModule.tags: 'TAGS', - AccessModule.triggers: 'TRIGGERS', - AccessModule.users: 'USERS', - AccessModule.reporttemplates: 'REPORTTEMPLATES', - AccessModule.charts: 'CHARTS', - AccessModule.visionProfiles: 'VISION_PROFILES', - AccessModule.cloudFile: 'CLOUD_FILE', - AccessModule.cloudFolder: 'CLOUD_FOLDER', - AccessModule.commands: 'COMMANDS', - AccessModule.workspaces: 'WORKSPACES', - AccessModule.emailTemplates: 'EMAIL_TEMPLATES', - AccessModule.brickhouseAlert: 'BRICKHOUSE_ALERT', - AccessModule.brickhouseUnit: 'BRICKHOUSE_UNIT', - AccessModule.sensors: 'SENSORS', - AccessModule.tagonBusRoutes: 'TAGON_BUS_ROUTES', - AccessModule.exchangeServices: 'EXCHANGE_SERVICES', - AccessModule.reportSchedulers: 'REPORT_SCHEDULERS', - AccessModule.atsMonitors: 'ATS_MONITORS', - AccessModule.unknown: 'UNKNOWN', -}; - -_AccessInput _$AccessInputFromJson(Map json) => _AccessInput( - id: json['id'] as String?, - read: json['read'] as bool? ?? false, - write: json['write'] as bool? ?? false, - manage: json['manage'] as bool? ?? false, - objectId: json['objectId'] as String?, - userId: json['userId'] as String?, - module: $enumDecode( - _$AccessModuleEnumMap, - json['module'], - unknownValue: AccessModule.unknown, - ), -); - -Map _$AccessInputToJson(_AccessInput instance) => - { - 'id': instance.id, - 'read': instance.read, - 'write': instance.write, - 'manage': instance.manage, - 'objectId': instance.objectId, - 'userId': instance.userId, - 'module': instance.module.toJson(), - }; - _LinkShortcut _$LinkShortcutFromJson(Map json) => _LinkShortcut( id: json['id'] as String, diff --git a/lib/src/access/access.dart b/lib/src/access/access.dart new file mode 100644 index 00000000..c618afa1 --- /dev/null +++ b/lib/src/access/access.dart @@ -0,0 +1,12 @@ +library; + +import 'package:collection/collection.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:layrz_models/layrz_models.dart'; + +part 'access.freezed.dart'; +part 'access.g.dart'; + +part 'src/access_module.dart'; +part 'src/access.dart'; +part 'src/access_input.dart'; diff --git a/lib/src/access/access.freezed.dart b/lib/src/access/access.freezed.dart new file mode 100644 index 00000000..98debca3 --- /dev/null +++ b/lib/src/access/access.freezed.dart @@ -0,0 +1,613 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'access.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +// dart format off +T _$identity(T value) => value; + +/// @nodoc +mixin _$Access { + + String get id; String? get label; bool? get read; bool? get write; bool? get manage; String? get objectId; String get userId; User? get user;@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule get module; +/// Create a copy of Access +/// with the given fields replaced by the non-null parameter values. +@JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +$AccessCopyWith get copyWith => _$AccessCopyWithImpl(this as Access, _$identity); + + /// Serializes this Access to a JSON map. + Map toJson(); + + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is Access&&(identical(other.id, id) || other.id == id)&&(identical(other.label, label) || other.label == label)&&(identical(other.read, read) || other.read == read)&&(identical(other.write, write) || other.write == write)&&(identical(other.manage, manage) || other.manage == manage)&&(identical(other.objectId, objectId) || other.objectId == objectId)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.user, user) || other.user == user)&&(identical(other.module, module) || other.module == module)); +} + +@JsonKey(includeFromJson: false, includeToJson: false) +@override +int get hashCode => Object.hash(runtimeType,id,label,read,write,manage,objectId,userId,user,module); + +@override +String toString() { + return 'Access(id: $id, label: $label, read: $read, write: $write, manage: $manage, objectId: $objectId, userId: $userId, user: $user, module: $module)'; +} + + +} + +/// @nodoc +abstract mixin class $AccessCopyWith<$Res> { + factory $AccessCopyWith(Access value, $Res Function(Access) _then) = _$AccessCopyWithImpl; +@useResult +$Res call({ + String id, String? label, bool? read, bool? write, bool? manage, String? objectId, String userId, User? user,@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module +}); + + +$UserCopyWith<$Res>? get user; + +} +/// @nodoc +class _$AccessCopyWithImpl<$Res> + implements $AccessCopyWith<$Res> { + _$AccessCopyWithImpl(this._self, this._then); + + final Access _self; + final $Res Function(Access) _then; + +/// Create a copy of Access +/// with the given fields replaced by the non-null parameter values. +@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? label = freezed,Object? read = freezed,Object? write = freezed,Object? manage = freezed,Object? objectId = freezed,Object? userId = null,Object? user = freezed,Object? module = null,}) { + return _then(_self.copyWith( +id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable +as String,label: freezed == label ? _self.label : label // ignore: cast_nullable_to_non_nullable +as String?,read: freezed == read ? _self.read : read // ignore: cast_nullable_to_non_nullable +as bool?,write: freezed == write ? _self.write : write // ignore: cast_nullable_to_non_nullable +as bool?,manage: freezed == manage ? _self.manage : manage // ignore: cast_nullable_to_non_nullable +as bool?,objectId: freezed == objectId ? _self.objectId : objectId // ignore: cast_nullable_to_non_nullable +as String?,userId: null == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable +as String,user: freezed == user ? _self.user : user // ignore: cast_nullable_to_non_nullable +as User?,module: null == module ? _self.module : module // ignore: cast_nullable_to_non_nullable +as AccessModule, + )); +} +/// Create a copy of Access +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$UserCopyWith<$Res>? get user { + if (_self.user == null) { + return null; + } + + return $UserCopyWith<$Res>(_self.user!, (value) { + return _then(_self.copyWith(user: value)); + }); +} +} + + +/// Adds pattern-matching-related methods to [Access]. +extension AccessPatterns on Access { +/// A variant of `map` that fallback to returning `orElse`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeMap(TResult Function( _Access value)? $default,{required TResult orElse(),}){ +final _that = this; +switch (_that) { +case _Access() when $default != null: +return $default(_that);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// Callbacks receives the raw object, upcasted. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case final Subclass2 value: +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult map(TResult Function( _Access value) $default,){ +final _that = this; +switch (_that) { +case _Access(): +return $default(_that);case _: + throw StateError('Unexpected subclass'); + +} +} +/// A variant of `map` that fallback to returning `null`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? mapOrNull(TResult? Function( _Access value)? $default,){ +final _that = this; +switch (_that) { +case _Access() when $default != null: +return $default(_that);case _: + return null; + +} +} +/// A variant of `when` that fallback to an `orElse` callback. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String? label, bool? read, bool? write, bool? manage, String? objectId, String userId, User? user, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module)? $default,{required TResult orElse(),}) {final _that = this; +switch (_that) { +case _Access() when $default != null: +return $default(_that.id,_that.label,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.user,_that.module);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// As opposed to `map`, this offers destructuring. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case Subclass2(:final field2): +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult when(TResult Function( String id, String? label, bool? read, bool? write, bool? manage, String? objectId, String userId, User? user, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module) $default,) {final _that = this; +switch (_that) { +case _Access(): +return $default(_that.id,_that.label,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.user,_that.module);case _: + throw StateError('Unexpected subclass'); + +} +} +/// A variant of `when` that fallback to returning `null` +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String? label, bool? read, bool? write, bool? manage, String? objectId, String userId, User? user, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module)? $default,) {final _that = this; +switch (_that) { +case _Access() when $default != null: +return $default(_that.id,_that.label,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.user,_that.module);case _: + return null; + +} +} + +} + +/// @nodoc +@JsonSerializable() + +class _Access implements Access { + const _Access({required this.id, this.label, this.read, this.write, this.manage, this.objectId, required this.userId, this.user, @JsonKey(unknownEnumValue: AccessModule.unknown) required this.module}); + factory _Access.fromJson(Map json) => _$AccessFromJson(json); + +@override final String id; +@override final String? label; +@override final bool? read; +@override final bool? write; +@override final bool? manage; +@override final String? objectId; +@override final String userId; +@override final User? user; +@override@JsonKey(unknownEnumValue: AccessModule.unknown) final AccessModule module; + +/// Create a copy of Access +/// with the given fields replaced by the non-null parameter values. +@override @JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +_$AccessCopyWith<_Access> get copyWith => __$AccessCopyWithImpl<_Access>(this, _$identity); + +@override +Map toJson() { + return _$AccessToJson(this, ); +} + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is _Access&&(identical(other.id, id) || other.id == id)&&(identical(other.label, label) || other.label == label)&&(identical(other.read, read) || other.read == read)&&(identical(other.write, write) || other.write == write)&&(identical(other.manage, manage) || other.manage == manage)&&(identical(other.objectId, objectId) || other.objectId == objectId)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.user, user) || other.user == user)&&(identical(other.module, module) || other.module == module)); +} + +@JsonKey(includeFromJson: false, includeToJson: false) +@override +int get hashCode => Object.hash(runtimeType,id,label,read,write,manage,objectId,userId,user,module); + +@override +String toString() { + return 'Access(id: $id, label: $label, read: $read, write: $write, manage: $manage, objectId: $objectId, userId: $userId, user: $user, module: $module)'; +} + + +} + +/// @nodoc +abstract mixin class _$AccessCopyWith<$Res> implements $AccessCopyWith<$Res> { + factory _$AccessCopyWith(_Access value, $Res Function(_Access) _then) = __$AccessCopyWithImpl; +@override @useResult +$Res call({ + String id, String? label, bool? read, bool? write, bool? manage, String? objectId, String userId, User? user,@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module +}); + + +@override $UserCopyWith<$Res>? get user; + +} +/// @nodoc +class __$AccessCopyWithImpl<$Res> + implements _$AccessCopyWith<$Res> { + __$AccessCopyWithImpl(this._self, this._then); + + final _Access _self; + final $Res Function(_Access) _then; + +/// Create a copy of Access +/// with the given fields replaced by the non-null parameter values. +@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? label = freezed,Object? read = freezed,Object? write = freezed,Object? manage = freezed,Object? objectId = freezed,Object? userId = null,Object? user = freezed,Object? module = null,}) { + return _then(_Access( +id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable +as String,label: freezed == label ? _self.label : label // ignore: cast_nullable_to_non_nullable +as String?,read: freezed == read ? _self.read : read // ignore: cast_nullable_to_non_nullable +as bool?,write: freezed == write ? _self.write : write // ignore: cast_nullable_to_non_nullable +as bool?,manage: freezed == manage ? _self.manage : manage // ignore: cast_nullable_to_non_nullable +as bool?,objectId: freezed == objectId ? _self.objectId : objectId // ignore: cast_nullable_to_non_nullable +as String?,userId: null == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable +as String,user: freezed == user ? _self.user : user // ignore: cast_nullable_to_non_nullable +as User?,module: null == module ? _self.module : module // ignore: cast_nullable_to_non_nullable +as AccessModule, + )); +} + +/// Create a copy of Access +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$UserCopyWith<$Res>? get user { + if (_self.user == null) { + return null; + } + + return $UserCopyWith<$Res>(_self.user!, (value) { + return _then(_self.copyWith(user: value)); + }); +} +} + + +/// @nodoc +mixin _$AccessInput { + +/// Represents the id of the access. + String? get id;/// Represents the id of the access. + set id(String? value);/// Represents the read permission. + bool get read;/// Represents the read permission. + set read(bool value);/// Represents the write permission. + bool get write;/// Represents the write permission. + set write(bool value);/// Represents the manage permission. + bool get manage;/// Represents the manage permission. + set manage(bool value);/// Represents the id of the object. + String? get objectId;/// Represents the id of the object. + set objectId(String? value);/// Represents the id of the user. + String? get userId;/// Represents the id of the user. + set userId(String? value);/// Represents the module of the access. +@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule get module;/// Represents the module of the access. +@JsonKey(unknownEnumValue: AccessModule.unknown) set module(AccessModule value); +/// Create a copy of AccessInput +/// with the given fields replaced by the non-null parameter values. +@JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +$AccessInputCopyWith get copyWith => _$AccessInputCopyWithImpl(this as AccessInput, _$identity); + + /// Serializes this AccessInput to a JSON map. + Map toJson(); + + + + +@override +String toString() { + return 'AccessInput(id: $id, read: $read, write: $write, manage: $manage, objectId: $objectId, userId: $userId, module: $module)'; +} + + +} + +/// @nodoc +abstract mixin class $AccessInputCopyWith<$Res> { + factory $AccessInputCopyWith(AccessInput value, $Res Function(AccessInput) _then) = _$AccessInputCopyWithImpl; +@useResult +$Res call({ + String? id, bool read, bool write, bool manage, String? objectId, String? userId,@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module +}); + + + + +} +/// @nodoc +class _$AccessInputCopyWithImpl<$Res> + implements $AccessInputCopyWith<$Res> { + _$AccessInputCopyWithImpl(this._self, this._then); + + final AccessInput _self; + final $Res Function(AccessInput) _then; + +/// Create a copy of AccessInput +/// with the given fields replaced by the non-null parameter values. +@pragma('vm:prefer-inline') @override $Res call({Object? id = freezed,Object? read = null,Object? write = null,Object? manage = null,Object? objectId = freezed,Object? userId = freezed,Object? module = null,}) { + return _then(_self.copyWith( +id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable +as String?,read: null == read ? _self.read : read // ignore: cast_nullable_to_non_nullable +as bool,write: null == write ? _self.write : write // ignore: cast_nullable_to_non_nullable +as bool,manage: null == manage ? _self.manage : manage // ignore: cast_nullable_to_non_nullable +as bool,objectId: freezed == objectId ? _self.objectId : objectId // ignore: cast_nullable_to_non_nullable +as String?,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable +as String?,module: null == module ? _self.module : module // ignore: cast_nullable_to_non_nullable +as AccessModule, + )); +} + +} + + +/// Adds pattern-matching-related methods to [AccessInput]. +extension AccessInputPatterns on AccessInput { +/// A variant of `map` that fallback to returning `orElse`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeMap(TResult Function( _AccessInput value)? $default,{required TResult orElse(),}){ +final _that = this; +switch (_that) { +case _AccessInput() when $default != null: +return $default(_that);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// Callbacks receives the raw object, upcasted. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case final Subclass2 value: +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult map(TResult Function( _AccessInput value) $default,){ +final _that = this; +switch (_that) { +case _AccessInput(): +return $default(_that);case _: + throw StateError('Unexpected subclass'); + +} +} +/// A variant of `map` that fallback to returning `null`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? mapOrNull(TResult? Function( _AccessInput value)? $default,){ +final _that = this; +switch (_that) { +case _AccessInput() when $default != null: +return $default(_that);case _: + return null; + +} +} +/// A variant of `when` that fallback to an `orElse` callback. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeWhen(TResult Function( String? id, bool read, bool write, bool manage, String? objectId, String? userId, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module)? $default,{required TResult orElse(),}) {final _that = this; +switch (_that) { +case _AccessInput() when $default != null: +return $default(_that.id,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.module);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// As opposed to `map`, this offers destructuring. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case Subclass2(:final field2): +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult when(TResult Function( String? id, bool read, bool write, bool manage, String? objectId, String? userId, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module) $default,) {final _that = this; +switch (_that) { +case _AccessInput(): +return $default(_that.id,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.module);case _: + throw StateError('Unexpected subclass'); + +} +} +/// A variant of `when` that fallback to returning `null` +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String? id, bool read, bool write, bool manage, String? objectId, String? userId, @JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module)? $default,) {final _that = this; +switch (_that) { +case _AccessInput() when $default != null: +return $default(_that.id,_that.read,_that.write,_that.manage,_that.objectId,_that.userId,_that.module);case _: + return null; + +} +} + +} + +/// @nodoc +@JsonSerializable() + +class _AccessInput implements AccessInput { + _AccessInput({this.id, this.read = false, this.write = false, this.manage = false, this.objectId, this.userId, @JsonKey(unknownEnumValue: AccessModule.unknown) required this.module}); + factory _AccessInput.fromJson(Map json) => _$AccessInputFromJson(json); + +/// Represents the id of the access. +@override String? id; +/// Represents the read permission. +@override@JsonKey() bool read; +/// Represents the write permission. +@override@JsonKey() bool write; +/// Represents the manage permission. +@override@JsonKey() bool manage; +/// Represents the id of the object. +@override String? objectId; +/// Represents the id of the user. +@override String? userId; +/// Represents the module of the access. +@override@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module; + +/// Create a copy of AccessInput +/// with the given fields replaced by the non-null parameter values. +@override @JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +_$AccessInputCopyWith<_AccessInput> get copyWith => __$AccessInputCopyWithImpl<_AccessInput>(this, _$identity); + +@override +Map toJson() { + return _$AccessInputToJson(this, ); +} + + + +@override +String toString() { + return 'AccessInput(id: $id, read: $read, write: $write, manage: $manage, objectId: $objectId, userId: $userId, module: $module)'; +} + + +} + +/// @nodoc +abstract mixin class _$AccessInputCopyWith<$Res> implements $AccessInputCopyWith<$Res> { + factory _$AccessInputCopyWith(_AccessInput value, $Res Function(_AccessInput) _then) = __$AccessInputCopyWithImpl; +@override @useResult +$Res call({ + String? id, bool read, bool write, bool manage, String? objectId, String? userId,@JsonKey(unknownEnumValue: AccessModule.unknown) AccessModule module +}); + + + + +} +/// @nodoc +class __$AccessInputCopyWithImpl<$Res> + implements _$AccessInputCopyWith<$Res> { + __$AccessInputCopyWithImpl(this._self, this._then); + + final _AccessInput _self; + final $Res Function(_AccessInput) _then; + +/// Create a copy of AccessInput +/// with the given fields replaced by the non-null parameter values. +@override @pragma('vm:prefer-inline') $Res call({Object? id = freezed,Object? read = null,Object? write = null,Object? manage = null,Object? objectId = freezed,Object? userId = freezed,Object? module = null,}) { + return _then(_AccessInput( +id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable +as String?,read: null == read ? _self.read : read // ignore: cast_nullable_to_non_nullable +as bool,write: null == write ? _self.write : write // ignore: cast_nullable_to_non_nullable +as bool,manage: null == manage ? _self.manage : manage // ignore: cast_nullable_to_non_nullable +as bool,objectId: freezed == objectId ? _self.objectId : objectId // ignore: cast_nullable_to_non_nullable +as String?,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable +as String?,module: null == module ? _self.module : module // ignore: cast_nullable_to_non_nullable +as AccessModule, + )); +} + + +} + +// dart format on diff --git a/lib/src/access/access.g.dart b/lib/src/access/access.g.dart new file mode 100644 index 00000000..25e1fd14 --- /dev/null +++ b/lib/src/access/access.g.dart @@ -0,0 +1,99 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'access.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_Access _$AccessFromJson(Map json) => _Access( + id: json['id'] as String, + label: json['label'] as String?, + read: json['read'] as bool?, + write: json['write'] as bool?, + manage: json['manage'] as bool?, + objectId: json['objectId'] as String?, + userId: json['userId'] as String, + user: json['user'] == null + ? null + : User.fromJson(json['user'] as Map), + module: $enumDecode( + _$AccessModuleEnumMap, + json['module'], + unknownValue: AccessModule.unknown, + ), +); + +Map _$AccessToJson(_Access instance) => { + 'id': instance.id, + 'label': instance.label, + 'read': instance.read, + 'write': instance.write, + 'manage': instance.manage, + 'objectId': instance.objectId, + 'userId': instance.userId, + 'user': instance.user?.toJson(), + 'module': instance.module.toJson(), +}; + +const _$AccessModuleEnumMap = { + AccessModule.actions: 'ACTIONS', + AccessModule.assets: 'ASSETS', + AccessModule.careprotocols: 'CAREPROTOCOLS', + AccessModule.checkpoints: 'CHECKPOINTS', + AccessModule.conciergeForms: 'CONCIERGE_FORMS', + AccessModule.coreprocess: 'COREPROCESS', + AccessModule.devices: 'DEVICES', + AccessModule.functions: 'FUNCTIONS', + AccessModule.geofences: 'GEOFENCES', + AccessModule.inboundServices: 'INBOUND_SERVICES', + AccessModule.operations: 'OPERATIONS', + AccessModule.outboundServices: 'OUTBOUND_SERVICES', + AccessModule.presets: 'PRESETS', + AccessModule.references: 'REFERENCES', + AccessModule.externalAccounts: 'EXTERNAL_ACCOUNTS', + AccessModule.tags: 'TAGS', + AccessModule.triggers: 'TRIGGERS', + AccessModule.users: 'USERS', + AccessModule.reporttemplates: 'REPORTTEMPLATES', + AccessModule.charts: 'CHARTS', + AccessModule.visionProfiles: 'VISION_PROFILES', + AccessModule.cloudFile: 'CLOUD_FILE', + AccessModule.cloudFolder: 'CLOUD_FOLDER', + AccessModule.commands: 'COMMANDS', + AccessModule.workspaces: 'WORKSPACES', + AccessModule.emailTemplates: 'EMAIL_TEMPLATES', + AccessModule.brickhouseAlert: 'BRICKHOUSE_ALERT', + AccessModule.brickhouseUnit: 'BRICKHOUSE_UNIT', + AccessModule.sensors: 'SENSORS', + AccessModule.tagonBusRoutes: 'TAGON_BUS_ROUTES', + AccessModule.exchangeServices: 'EXCHANGE_SERVICES', + AccessModule.reportSchedulers: 'REPORT_SCHEDULERS', + AccessModule.atsMonitors: 'ATS_MONITORS', + AccessModule.unknown: 'UNKNOWN', +}; + +_AccessInput _$AccessInputFromJson(Map json) => _AccessInput( + id: json['id'] as String?, + read: json['read'] as bool? ?? false, + write: json['write'] as bool? ?? false, + manage: json['manage'] as bool? ?? false, + objectId: json['objectId'] as String?, + userId: json['userId'] as String?, + module: $enumDecode( + _$AccessModuleEnumMap, + json['module'], + unknownValue: AccessModule.unknown, + ), +); + +Map _$AccessInputToJson(_AccessInput instance) => + { + 'id': instance.id, + 'read': instance.read, + 'write': instance.write, + 'manage': instance.manage, + 'objectId': instance.objectId, + 'userId': instance.userId, + 'module': instance.module.toJson(), + }; diff --git a/lib/src/access/src/access.dart b/lib/src/access/src/access.dart new file mode 100644 index 00000000..1e258825 --- /dev/null +++ b/lib/src/access/src/access.dart @@ -0,0 +1,21 @@ +part of '../access.dart'; + +@freezed + +/// AccessPermission +/// Access Permission class +abstract class Access with _$Access { + const factory Access({ + required String id, + String? label, + bool? read, + bool? write, + bool? manage, + String? objectId, + required String userId, + User? user, + @JsonKey(unknownEnumValue: AccessModule.unknown) required AccessModule module, + }) = _Access; + + factory Access.fromJson(Map json) => _$AccessFromJson(json); +} diff --git a/lib/src/access/src/access_input.dart b/lib/src/access/src/access_input.dart new file mode 100644 index 00000000..21dc30cd --- /dev/null +++ b/lib/src/access/src/access_input.dart @@ -0,0 +1,29 @@ +part of '../access.dart'; + +@unfreezed +abstract class AccessInput with _$AccessInput { + factory AccessInput({ + /// Represents the id of the access. + String? id, + + /// Represents the read permission. + @Default(false) bool read, + + /// Represents the write permission. + @Default(false) bool write, + + /// Represents the manage permission. + @Default(false) bool manage, + + /// Represents the id of the object. + String? objectId, + + /// Represents the id of the user. + String? userId, + + /// Represents the module of the access. + @JsonKey(unknownEnumValue: AccessModule.unknown) required AccessModule module, + }) = _AccessInput; + + factory AccessInput.fromJson(Map json) => _$AccessInputFromJson(json); +} diff --git a/lib/src/access.dart b/lib/src/access/src/access_module.dart similarity index 78% rename from lib/src/access.dart rename to lib/src/access/src/access_module.dart index c7ce232a..3baed695 100644 --- a/lib/src/access.dart +++ b/lib/src/access/src/access_module.dart @@ -1,4 +1,4 @@ -part of '../layrz_models.dart'; +part of '../access.dart'; enum AccessModule { /// Access to actions module @@ -181,51 +181,3 @@ enum AccessModule { return found?.key ?? AccessModule.unknown; } } - -@freezed - -/// AccessPermission -/// Access Permission class -abstract class Access with _$Access { - const factory Access({ - required String id, - String? label, - bool? read, - bool? write, - bool? manage, - String? objectId, - required String userId, - User? user, - @JsonKey(unknownEnumValue: AccessModule.unknown) required AccessModule module, - }) = _Access; - - factory Access.fromJson(Map json) => _$AccessFromJson(json); -} - -@unfreezed -abstract class AccessInput with _$AccessInput { - factory AccessInput({ - /// Represents the id of the access. - String? id, - - /// Represents the read permission. - @Default(false) bool read, - - /// Represents the write permission. - @Default(false) bool write, - - /// Represents the manage permission. - @Default(false) bool manage, - - /// Represents the id of the object. - String? objectId, - - /// Represents the id of the user. - String? userId, - - /// Represents the module of the access. - @JsonKey(unknownEnumValue: AccessModule.unknown) required AccessModule module, - }) = _AccessInput; - - factory AccessInput.fromJson(Map json) => _$AccessInputFromJson(json); -} diff --git a/lib/src/map/map.dart b/lib/src/map/map.dart index 2c1bc4ff..c3967bae 100644 --- a/lib/src/map/map.dart +++ b/lib/src/map/map.dart @@ -2,6 +2,11 @@ library; import 'package:collection/collection.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:layrz_icons/layrz_icons.dart'; +import 'package:layrz_logging/layrz_logging.dart'; +import 'package:layrz_models/src/access/access.dart'; +import 'package:layrz_models/src/converters/converters.dart'; +import 'package:layrz_models/src/utils/src/api_connector.dart'; // Freezed part 'map.freezed.dart'; @@ -14,3 +19,11 @@ part 'src/google_layer.dart'; part 'src/mapbox_style.dart'; part 'src/map_source.dart'; part 'src/poi.dart'; +part 'src/poi_input.dart'; + +class PoiApiResponse { + final Poi? poi; + final Map errors; + + PoiApiResponse({this.poi, this.errors = const {}}); +} diff --git a/lib/src/map/map.freezed.dart b/lib/src/map/map.freezed.dart index 9aeefd29..2d8ec72b 100644 --- a/lib/src/map/map.freezed.dart +++ b/lib/src/map/map.freezed.dart @@ -821,9 +821,11 @@ mixin _$Poi { /// [id] is the unique identifier for the point of interest. String get id;/// [name] is the name of the point of interest. String get name;/// [description] is the description of the point of interest. - String? get description;/// [latitude] is the latitude of the point of interest. - double get latitude;/// [longitude] is the longitude of the point of interest. - double get longitude; + String? get description;/// [icon] is the icon representing the point of interest. +@IconOrNullConverter() LayrzIcon? get icon;/// [latitude] is the latitude of the point of interest. + double? get latitude;/// [longitude] is the longitude of the point of interest. + double? get longitude;/// [access] is the user access to this point of interest. + List? get access; /// Create a copy of Poi /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -836,16 +838,16 @@ $PoiCopyWith get copyWith => _$PoiCopyWithImpl(this as Poi, _$identity @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is Poi&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&(identical(other.latitude, latitude) || other.latitude == latitude)&&(identical(other.longitude, longitude) || other.longitude == longitude)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is Poi&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&(identical(other.icon, icon) || other.icon == icon)&&(identical(other.latitude, latitude) || other.latitude == latitude)&&(identical(other.longitude, longitude) || other.longitude == longitude)&&const DeepCollectionEquality().equals(other.access, access)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,id,name,description,latitude,longitude); +int get hashCode => Object.hash(runtimeType,id,name,description,icon,latitude,longitude,const DeepCollectionEquality().hash(access)); @override String toString() { - return 'Poi(id: $id, name: $name, description: $description, latitude: $latitude, longitude: $longitude)'; + return 'Poi(id: $id, name: $name, description: $description, icon: $icon, latitude: $latitude, longitude: $longitude, access: $access)'; } @@ -856,7 +858,7 @@ abstract mixin class $PoiCopyWith<$Res> { factory $PoiCopyWith(Poi value, $Res Function(Poi) _then) = _$PoiCopyWithImpl; @useResult $Res call({ - String id, String name, String? description, double latitude, double longitude + String id, String name, String? description,@IconOrNullConverter() LayrzIcon? icon, double? latitude, double? longitude, List? access }); @@ -873,14 +875,16 @@ class _$PoiCopyWithImpl<$Res> /// Create a copy of Poi /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,Object? description = freezed,Object? latitude = null,Object? longitude = null,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,Object? description = freezed,Object? icon = freezed,Object? latitude = freezed,Object? longitude = freezed,Object? access = freezed,}) { return _then(_self.copyWith( id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable -as String?,latitude: null == latitude ? _self.latitude : latitude // ignore: cast_nullable_to_non_nullable -as double,longitude: null == longitude ? _self.longitude : longitude // ignore: cast_nullable_to_non_nullable -as double, +as String?,icon: freezed == icon ? _self.icon : icon // ignore: cast_nullable_to_non_nullable +as LayrzIcon?,latitude: freezed == latitude ? _self.latitude : latitude // ignore: cast_nullable_to_non_nullable +as double?,longitude: freezed == longitude ? _self.longitude : longitude // ignore: cast_nullable_to_non_nullable +as double?,access: freezed == access ? _self.access : access // ignore: cast_nullable_to_non_nullable +as List?, )); } @@ -965,10 +969,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String name, String? description, double latitude, double longitude)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String name, String? description, @IconOrNullConverter() LayrzIcon? icon, double? latitude, double? longitude, List? access)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _Poi() when $default != null: -return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longitude);case _: +return $default(_that.id,_that.name,_that.description,_that.icon,_that.latitude,_that.longitude,_that.access);case _: return orElse(); } @@ -986,10 +990,10 @@ return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longi /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String id, String name, String? description, double latitude, double longitude) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String id, String name, String? description, @IconOrNullConverter() LayrzIcon? icon, double? latitude, double? longitude, List? access) $default,) {final _that = this; switch (_that) { case _Poi(): -return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longitude);case _: +return $default(_that.id,_that.name,_that.description,_that.icon,_that.latitude,_that.longitude,_that.access);case _: throw StateError('Unexpected subclass'); } @@ -1006,10 +1010,10 @@ return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longi /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String name, String? description, double latitude, double longitude)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String name, String? description, @IconOrNullConverter() LayrzIcon? icon, double? latitude, double? longitude, List? access)? $default,) {final _that = this; switch (_that) { case _Poi() when $default != null: -return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longitude);case _: +return $default(_that.id,_that.name,_that.description,_that.icon,_that.latitude,_that.longitude,_that.access);case _: return null; } @@ -1020,8 +1024,8 @@ return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longi /// @nodoc @JsonSerializable() -class _Poi implements Poi { - const _Poi({required this.id, required this.name, this.description, required this.latitude, required this.longitude}); +class _Poi extends Poi { + const _Poi({required this.id, required this.name, this.description, @IconOrNullConverter() this.icon, this.latitude, this.longitude, final List? access}): _access = access,super._(); factory _Poi.fromJson(Map json) => _$PoiFromJson(json); /// [id] is the unique identifier for the point of interest. @@ -1030,10 +1034,23 @@ class _Poi implements Poi { @override final String name; /// [description] is the description of the point of interest. @override final String? description; +/// [icon] is the icon representing the point of interest. +@override@IconOrNullConverter() final LayrzIcon? icon; /// [latitude] is the latitude of the point of interest. -@override final double latitude; +@override final double? latitude; /// [longitude] is the longitude of the point of interest. -@override final double longitude; +@override final double? longitude; +/// [access] is the user access to this point of interest. + final List? _access; +/// [access] is the user access to this point of interest. +@override List? get access { + final value = _access; + if (value == null) return null; + if (_access is EqualUnmodifiableListView) return _access; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); +} + /// Create a copy of Poi /// with the given fields replaced by the non-null parameter values. @@ -1048,16 +1065,16 @@ Map toJson() { @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _Poi&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&(identical(other.latitude, latitude) || other.latitude == latitude)&&(identical(other.longitude, longitude) || other.longitude == longitude)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _Poi&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&(identical(other.icon, icon) || other.icon == icon)&&(identical(other.latitude, latitude) || other.latitude == latitude)&&(identical(other.longitude, longitude) || other.longitude == longitude)&&const DeepCollectionEquality().equals(other._access, _access)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,id,name,description,latitude,longitude); +int get hashCode => Object.hash(runtimeType,id,name,description,icon,latitude,longitude,const DeepCollectionEquality().hash(_access)); @override String toString() { - return 'Poi(id: $id, name: $name, description: $description, latitude: $latitude, longitude: $longitude)'; + return 'Poi(id: $id, name: $name, description: $description, icon: $icon, latitude: $latitude, longitude: $longitude, access: $access)'; } @@ -1068,7 +1085,7 @@ abstract mixin class _$PoiCopyWith<$Res> implements $PoiCopyWith<$Res> { factory _$PoiCopyWith(_Poi value, $Res Function(_Poi) _then) = __$PoiCopyWithImpl; @override @useResult $Res call({ - String id, String name, String? description, double latitude, double longitude + String id, String name, String? description,@IconOrNullConverter() LayrzIcon? icon, double? latitude, double? longitude, List? access }); @@ -1085,14 +1102,16 @@ class __$PoiCopyWithImpl<$Res> /// Create a copy of Poi /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,Object? description = freezed,Object? latitude = null,Object? longitude = null,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,Object? description = freezed,Object? icon = freezed,Object? latitude = freezed,Object? longitude = freezed,Object? access = freezed,}) { return _then(_Poi( id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable -as String?,latitude: null == latitude ? _self.latitude : latitude // ignore: cast_nullable_to_non_nullable -as double,longitude: null == longitude ? _self.longitude : longitude // ignore: cast_nullable_to_non_nullable -as double, +as String?,icon: freezed == icon ? _self.icon : icon // ignore: cast_nullable_to_non_nullable +as LayrzIcon?,latitude: freezed == latitude ? _self.latitude : latitude // ignore: cast_nullable_to_non_nullable +as double?,longitude: freezed == longitude ? _self.longitude : longitude // ignore: cast_nullable_to_non_nullable +as double?,access: freezed == access ? _self._access : access // ignore: cast_nullable_to_non_nullable +as List?, )); } @@ -1109,11 +1128,13 @@ mixin _$PoiInput { String get name;/// [name] is the name of the point of interest. set name(String value);/// [description] is the description of the point of interest. String? get description;/// [description] is the description of the point of interest. - set description(String? value);/// [latitude] is the latitude of the point of interest. - double get latitude;/// [latitude] is the latitude of the point of interest. - set latitude(double value);/// [longitude] is the longitude of the point of interest. - double get longitude;/// [longitude] is the longitude of the point of interest. - set longitude(double value); + set description(String? value);/// [icon] is the icon representing the point of interest. +@IconConverter() LayrzIcon get icon;/// [icon] is the icon representing the point of interest. +@IconConverter() set icon(LayrzIcon value);/// [latitude] is the latitude of the point of interest. + double? get latitude;/// [latitude] is the latitude of the point of interest. + set latitude(double? value);/// [longitude] is the longitude of the point of interest. + double? get longitude;/// [longitude] is the longitude of the point of interest. + set longitude(double? value); /// Create a copy of PoiInput /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -1128,7 +1149,7 @@ $PoiInputCopyWith get copyWith => _$PoiInputCopyWithImpl(thi @override String toString() { - return 'PoiInput(id: $id, name: $name, description: $description, latitude: $latitude, longitude: $longitude)'; + return 'PoiInput(id: $id, name: $name, description: $description, icon: $icon, latitude: $latitude, longitude: $longitude)'; } @@ -1139,7 +1160,7 @@ abstract mixin class $PoiInputCopyWith<$Res> { factory $PoiInputCopyWith(PoiInput value, $Res Function(PoiInput) _then) = _$PoiInputCopyWithImpl; @useResult $Res call({ - String? id, String name, String? description, double latitude, double longitude + String? id, String name, String? description,@IconConverter() LayrzIcon icon, double? latitude, double? longitude }); @@ -1156,14 +1177,15 @@ class _$PoiInputCopyWithImpl<$Res> /// Create a copy of PoiInput /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? id = freezed,Object? name = null,Object? description = freezed,Object? latitude = null,Object? longitude = null,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? id = freezed,Object? name = null,Object? description = freezed,Object? icon = null,Object? latitude = freezed,Object? longitude = freezed,}) { return _then(_self.copyWith( id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String?,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable -as String?,latitude: null == latitude ? _self.latitude : latitude // ignore: cast_nullable_to_non_nullable -as double,longitude: null == longitude ? _self.longitude : longitude // ignore: cast_nullable_to_non_nullable -as double, +as String?,icon: null == icon ? _self.icon : icon // ignore: cast_nullable_to_non_nullable +as LayrzIcon,latitude: freezed == latitude ? _self.latitude : latitude // ignore: cast_nullable_to_non_nullable +as double?,longitude: freezed == longitude ? _self.longitude : longitude // ignore: cast_nullable_to_non_nullable +as double?, )); } @@ -1248,10 +1270,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( String? id, String name, String? description, double latitude, double longitude)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String? id, String name, String? description, @IconConverter() LayrzIcon icon, double? latitude, double? longitude)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _PoiInput() when $default != null: -return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longitude);case _: +return $default(_that.id,_that.name,_that.description,_that.icon,_that.latitude,_that.longitude);case _: return orElse(); } @@ -1269,10 +1291,10 @@ return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longi /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String? id, String name, String? description, double latitude, double longitude) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String? id, String name, String? description, @IconConverter() LayrzIcon icon, double? latitude, double? longitude) $default,) {final _that = this; switch (_that) { case _PoiInput(): -return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longitude);case _: +return $default(_that.id,_that.name,_that.description,_that.icon,_that.latitude,_that.longitude);case _: throw StateError('Unexpected subclass'); } @@ -1289,10 +1311,10 @@ return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longi /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String? id, String name, String? description, double latitude, double longitude)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String? id, String name, String? description, @IconConverter() LayrzIcon icon, double? latitude, double? longitude)? $default,) {final _that = this; switch (_that) { case _PoiInput() when $default != null: -return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longitude);case _: +return $default(_that.id,_that.name,_that.description,_that.icon,_that.latitude,_that.longitude);case _: return null; } @@ -1303,8 +1325,8 @@ return $default(_that.id,_that.name,_that.description,_that.latitude,_that.longi /// @nodoc @JsonSerializable() -class _PoiInput implements PoiInput { - _PoiInput({this.id, this.name = '', this.description, this.latitude = 0.0, this.longitude = 0.0}); +class _PoiInput extends PoiInput { + _PoiInput({this.id, this.name = '', this.description, @IconConverter() required this.icon, this.latitude, this.longitude}): super._(); factory _PoiInput.fromJson(Map json) => _$PoiInputFromJson(json); /// [id] is the unique identifier for the point of interest. @@ -1313,10 +1335,12 @@ class _PoiInput implements PoiInput { @override@JsonKey() String name; /// [description] is the description of the point of interest. @override String? description; +/// [icon] is the icon representing the point of interest. +@override@IconConverter() LayrzIcon icon; /// [latitude] is the latitude of the point of interest. -@override@JsonKey() double latitude; +@override double? latitude; /// [longitude] is the longitude of the point of interest. -@override@JsonKey() double longitude; +@override double? longitude; /// Create a copy of PoiInput /// with the given fields replaced by the non-null parameter values. @@ -1333,7 +1357,7 @@ Map toJson() { @override String toString() { - return 'PoiInput(id: $id, name: $name, description: $description, latitude: $latitude, longitude: $longitude)'; + return 'PoiInput(id: $id, name: $name, description: $description, icon: $icon, latitude: $latitude, longitude: $longitude)'; } @@ -1344,7 +1368,7 @@ abstract mixin class _$PoiInputCopyWith<$Res> implements $PoiInputCopyWith<$Res> factory _$PoiInputCopyWith(_PoiInput value, $Res Function(_PoiInput) _then) = __$PoiInputCopyWithImpl; @override @useResult $Res call({ - String? id, String name, String? description, double latitude, double longitude + String? id, String name, String? description,@IconConverter() LayrzIcon icon, double? latitude, double? longitude }); @@ -1361,14 +1385,15 @@ class __$PoiInputCopyWithImpl<$Res> /// Create a copy of PoiInput /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? id = freezed,Object? name = null,Object? description = freezed,Object? latitude = null,Object? longitude = null,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? id = freezed,Object? name = null,Object? description = freezed,Object? icon = null,Object? latitude = freezed,Object? longitude = freezed,}) { return _then(_PoiInput( id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String?,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable -as String?,latitude: null == latitude ? _self.latitude : latitude // ignore: cast_nullable_to_non_nullable -as double,longitude: null == longitude ? _self.longitude : longitude // ignore: cast_nullable_to_non_nullable -as double, +as String?,icon: null == icon ? _self.icon : icon // ignore: cast_nullable_to_non_nullable +as LayrzIcon,latitude: freezed == latitude ? _self.latitude : latitude // ignore: cast_nullable_to_non_nullable +as double?,longitude: freezed == longitude ? _self.longitude : longitude // ignore: cast_nullable_to_non_nullable +as double?, )); } diff --git a/lib/src/map/map.g.dart b/lib/src/map/map.g.dart index 8ff9d66f..28329f3b 100644 --- a/lib/src/map/map.g.dart +++ b/lib/src/map/map.g.dart @@ -194,30 +194,38 @@ _Poi _$PoiFromJson(Map json) => _Poi( id: json['id'] as String, name: json['name'] as String, description: json['description'] as String?, - latitude: (json['latitude'] as num).toDouble(), - longitude: (json['longitude'] as num).toDouble(), + icon: const IconOrNullConverter().fromJson(json['icon'] as String?), + latitude: (json['latitude'] as num?)?.toDouble(), + longitude: (json['longitude'] as num?)?.toDouble(), + access: (json['access'] as List?) + ?.map((e) => Access.fromJson(e as Map)) + .toList(), ); Map _$PoiToJson(_Poi instance) => { 'id': instance.id, 'name': instance.name, 'description': instance.description, + 'icon': const IconOrNullConverter().toJson(instance.icon), 'latitude': instance.latitude, 'longitude': instance.longitude, + 'access': instance.access?.map((e) => e.toJson()).toList(), }; _PoiInput _$PoiInputFromJson(Map json) => _PoiInput( id: json['id'] as String?, name: json['name'] as String? ?? '', description: json['description'] as String?, - latitude: (json['latitude'] as num?)?.toDouble() ?? 0.0, - longitude: (json['longitude'] as num?)?.toDouble() ?? 0.0, + icon: const IconConverter().fromJson(json['icon'] as String), + latitude: (json['latitude'] as num?)?.toDouble(), + longitude: (json['longitude'] as num?)?.toDouble(), ); Map _$PoiInputToJson(_PoiInput instance) => { 'id': instance.id, 'name': instance.name, 'description': instance.description, + 'icon': const IconConverter().toJson(instance.icon), 'latitude': instance.latitude, 'longitude': instance.longitude, }; diff --git a/lib/src/map/src/poi.dart b/lib/src/map/src/poi.dart index 89dabaff..51f61db8 100644 --- a/lib/src/map/src/poi.dart +++ b/lib/src/map/src/poi.dart @@ -2,6 +2,8 @@ part of '../map.dart'; @freezed abstract class Poi with _$Poi { + const Poi._(); + /// [Poi] is the model for a point of interest. /// It is used to define the points of interest that can be used on maps const factory Poi({ @@ -14,37 +16,216 @@ abstract class Poi with _$Poi { /// [description] is the description of the point of interest. String? description, + /// [icon] is the icon representing the point of interest. + @IconOrNullConverter() LayrzIcon? icon, + /// [latitude] is the latitude of the point of interest. - required double latitude, + double? latitude, /// [longitude] is the longitude of the point of interest. - required double longitude, + double? longitude, + + /// [access] is the user access to this point of interest. + List? access, }) = _Poi; factory Poi.fromJson(Map json) => _$PoiFromJson(json); -} -@unfreezed -abstract class PoiInput with _$PoiInput { - /// [PoiInput] is the model for a point of interest. - /// It is used to define the points of interest that can be used on maps. - /// This model only can be getted from the [RegisteredApp] model. - factory PoiInput({ - /// [id] is the unique identifier for the point of interest. - String? id, + /// [fetch] fetches a single point of interest from the server by its ID + /// It returns a list of [Poi] with the required contextual information + Future fetch({ + /// [apiToken] is the API token to use for authentication. You can get one using the `login` mutation + /// on the GraphQL API. + required String apiToken, - /// [name] is the name of the point of interest. - @Default('') String name, + /// [uri] is the GraphQL endpoint to use + required Uri uri, - /// [description] is the description of the point of interest. - String? description, + /// [onResponse] is the callback to call when the response is received + void Function(String statusCode)? onResponse, + }) async { + final connector = LayrzConnector(uri: uri); + try { + final response = await connector.perform(query: fetchSingleQuery, variables: {'apiToken': apiToken, 'id': id}); - /// [latitude] is the latitude of the point of interest. - @Default(0.0) double latitude, + final data = response.data; + if (data == null) { + onResponse?.call('INTERNAL_ERROR'); + Log.error("layrz_models/Poi/fetch(): No response from server"); + return null; + } - /// [longitude] is the longitude of the point of interest. - @Default(0.0) double longitude, - }) = _PoiInput; + final result = data['data']['pois']; + if (result == null) { + onResponse?.call('INTERNAL_ERROR'); + Log.error("layrz_models/Poi/fetch(): No result from server"); + return null; + } + + if (result['status'] != 'OK') { + onResponse?.call(result['status']); + return null; + } + if (result['result'] == null || (result['result'] as List).isEmpty) { + onResponse?.call('NOT_FOUND'); + return null; + } + + return Poi.fromJson(Map.from(result['result'][0] as Map)); + } catch (e, stack) { + Log.critical("layrz_models/Poi/fetch(): General exception => $e\n$stack"); + return null; + } + } + + /// [fetchAll] fetches all POIs from the server + /// It returns a list of [Poi] with the required contextual information + static Future> fetchAll({ + /// [apiToken] is the API token to use for authentication. You can get one using the `login` mutation + /// on the GraphQL API. + required String apiToken, + + /// [uri] is the GraphQL endpoint to use + required Uri uri, + + /// [onResponse] is the callback to call when the response is received + void Function(String statusCode)? onResponse, + }) async { + final connector = LayrzConnector(uri: uri); + try { + final response = await connector.perform(query: fetchAllGraphqlQuery, variables: {'apiToken': apiToken}); + + final data = response.data; + if (data == null) { + onResponse?.call('INTERNAL_ERROR'); + Log.error("layrz_models/Poi/fetchAll(): No response from server"); + return []; + } + + final result = data['data']['pois']; + if (result == null) { + onResponse?.call('INTERNAL_ERROR'); + Log.error("layrz_models/Poi/fetchAll(): No result from server"); + return []; + } + + if (result['status'] != 'OK') { + onResponse?.call(result['status']); + return []; + } + + return (result['result'] as List?) + ?.map((e) => Poi.fromJson(Map.from(e as Map))) + .toList() ?? + []; + } catch (e, stack) { + Log.critical("layrz_models/Poi/fetchAll(): General exception => $e\n$stack"); + return []; + } + } + + /// [delete] deletes multiple POIs from the server by their IDs + static Future delete({ + /// [apiToken] is the API token to use for authentication. You can get one using the `login` mutation + /// on the GraphQL API. + required String apiToken, + + /// [uri] is the GraphQL endpoint to use + required Uri uri, + + /// [ids] is the list of POI IDs to delete + required List ids, + + /// [onResponse] is the callback to call when the response is received + void Function(String statusCode)? onResponse, + }) async { + final connector = LayrzConnector(uri: uri); + + try { + final response = await connector.perform( + query: deletePois, + variables: {'apiToken': apiToken, 'ids': ids}, + ); + + final data = response.data; + if (data == null) { + onResponse?.call('INTERNAL_ERROR'); + Log.error("layrz_models/Poi/delete(): No response from server"); + return false; + } + + final result = data['data']['deletePois']; + if (result == null) { + onResponse?.call('INTERNAL_ERROR'); + Log.error("layrz_models/Poi/delete(): No result from server"); + return false; + } + + if (result['status'] != 'OK') { + onResponse?.call(result['status']); + return false; + } + + return true; + } catch (e, stack) { + Log.critical("layrz_models/Poi/delete(): General exception => $e\n$stack"); + return false; + } + } + + /// [fetchSingleQuery] is the GraphQL query to fetch a single POI by its ID + /// It uses the [Poi.graphqlFragment] to get the POI data + static String get fetchSingleQuery => + '${Poi.graphqlFragment}' + r''' + query pois($apiToken: String!, $id: ID) { + pois(apiToken: $apiToken, id: $id) { + status + errors + result { + ...poiFragment + } + } + } + '''; + + /// [fetchAllGraphqlQuery] is the GraphQL query to fetch all POIs + /// It includes the basic user fields fragment [basicUserFields] to get the user data + /// It does not use the [Poi.graphqlFragment] to reduce the amount of data + static String get fetchAllGraphqlQuery => r''' + query pois($apiToken: String!) { + pois(apiToken: $apiToken) { + status + errors + result { + id + name + icon + } + } + } + '''; + + /// [graphqlFragment] is the GraphQL fragment to fetch the POI data + /// It includes the basic user fields fragment [basicUserFields] to get the user data + static String get graphqlFragment => ''' + fragment poiFragment on Poi { + id + name + description + icon + latitude + longitude + } + '''; - factory PoiInput.fromJson(Map json) => _$PoiInputFromJson(json); + /// [deletePois] is the GraphQL mutation to delete one or more POIs by their IDs + static String get deletePois => r''' + mutation deletePois($apiToken: String!, $ids: [ID!]!) { + deletePois(apiToken: $apiToken, ids: $ids) { + status + errors + } + } + '''; } diff --git a/lib/src/map/src/poi_input.dart b/lib/src/map/src/poi_input.dart new file mode 100644 index 00000000..e2975e57 --- /dev/null +++ b/lib/src/map/src/poi_input.dart @@ -0,0 +1,109 @@ +part of '../map.dart'; + +@unfreezed +abstract class PoiInput with _$PoiInput { + const PoiInput._(); + + /// [PoiInput] is the model for a point of interest. + /// It is used to define the points of interest that can be used on maps. + /// This model is used to create or update a point of interest via the GraphQL API. + factory PoiInput({ + /// [id] is the unique identifier for the point of interest. + String? id, + + /// [name] is the name of the point of interest. + @Default('') String name, + + /// [description] is the description of the point of interest. + String? description, + + /// [icon] is the icon representing the point of interest. + @IconConverter() required LayrzIcon icon, + + /// [latitude] is the latitude of the point of interest. + double? latitude, + + /// [longitude] is the longitude of the point of interest. + double? longitude, + }) = _PoiInput; + + factory PoiInput.fromJson(Map json) => _$PoiInputFromJson(json); + + /// [save] saves the POI input to the server + /// It returns a [PoiApiResponse] with the saved POI or errors if any + Future save({ + /// [apiToken] is the API token to use for authentication. You can get one using the `login` mutation + /// on the GraphQL API. + required String apiToken, + + /// [uri] is the GraphQL endpoint to use + required Uri uri, + + /// [onResponse] is the callback to call when the response is received + void Function(String statusCode)? onResponse, + }) async { + final connector = LayrzConnector(uri: uri); + try { + final response = await connector.perform( + query: id == null ? addGraphqlMutation : editGraphqlMutation, + variables: {'apiToken': apiToken, 'data': toJson()}, + ); + + final data = response.data; + if (data == null) { + onResponse?.call('INTERNAL_ERROR'); + Log.error("layrz_models/PoiInput/save(): No response from server"); + return null; + } + + final result = id == null ? data['data']['addPoi'] : data['data']['editPoi']; + if (result == null) { + onResponse?.call('INTERNAL_ERROR'); + Log.error("layrz_models/PoiInput/save(): No result from server"); + return null; + } + + if (result['status'] != 'OK') { + onResponse?.call(result['status']); + return PoiApiResponse(errors: Map.from(result['errors'] ?? {})); + } + + return PoiApiResponse(poi: Poi.fromJson(result['result'])); + } catch (e, stack) { + Log.critical("layrz_models/PoiInput/save(): General exception => $e\n$stack"); + return null; + } + } + + /// [addGraphqlMutation] is the GraphQL mutation to add a POI + /// It uses the [Poi.graphqlFragment] to get the POI data + static String get addGraphqlMutation => + '${Poi.graphqlFragment}' + r''' + mutation addPoi($apiToken: String!, $data: PoiInput!) { + addPoi(data: $data, apiToken: $apiToken) { + status + errors + result { + ...poiFragment + } + } + } + '''; + + /// [editGraphqlMutation] is the GraphQL mutation to edit a POI + /// It uses the [Poi.graphqlFragment] to get the POI data + static String get editGraphqlMutation => + '${Poi.graphqlFragment}' + r''' + mutation editPoi($apiToken: String!, $data: PoiInput!) { + editPoi(data: $data, apiToken: $apiToken) { + status + errors + result { + ...poiFragment + } + } + } + '''; +} diff --git a/pubspec.yaml b/pubspec.yaml index 4889c101..5dcf92db 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ description: Layrz API models for Dart/Flutter. This package contains the models used by the Layrz API. name: layrz_models -version: "3.6.20" +version: "3.6.21" repository: https://github.com/goldenm-software/layrz_models environment: