# MauiStorageService

- File ID: file:d17zn6:mauistorageservice-cs
- Path: NexusReader.Infrastructure.Mobile/Services/MauiStorageService.cs
- Role: service
- Layer: infrastructure

## Purpose

Provides a MAUI-specific implementation of INativeStorageService that wraps Preferences and SecureStorage to persist simple keys/values, returning FluentResults and converting exceptions to failure results.

## Key Details

Synchronous Preferences calls are wrapped in Task.FromResult; secure storage calls are awaited. All methods catch Exception and convert to Result.Fail(ex.Message), exposing exception messages as failure reasons.

## Symbols

- MauiStorageService: Provides a MAUI-specific implementation of INativeStorageService that wraps Preferences and SecureStorage to persist simple keys/values, returning FluentResults and converting exceptions to failure results.
- SaveStringAsync(): Saves a string value to MAUI Preferences under the provided key and returns a Fluent Result indicating success or failure.
- GetStringAsync(): Reads a string from MAUI Preferences for the given key and returns the value wrapped in a Fluent Result.
- SaveBoolAsync(): Saves a boolean value to MAUI Preferences and returns success/failure as a Fluent Result.
- GetBoolAsync(): Reads a boolean from MAUI Preferences with an optional default and returns it wrapped in a Fluent Result.
- RemoveAsync(): Removes a key from MAUI Preferences and returns a Fluent Result indicating success or failure.
- SaveSecureString(): Asynchronously saves a string to MAUI SecureStorage and returns a Fluent Result for success/failure.
- GetSecureString(): Asynchronously retrieves a string from MAUI SecureStorage and returns it wrapped in a Fluent Result.
- RemoveSecureAsync(): Removes a key from MAUI SecureStorage and returns a Fluent Result indicating success or failure.
- MauiStorageService: Concrete MAUI implementation of INativeStorageService that adapts Preferences and SecureStorage to the application's storage abstraction.

## Dependencies

- No resolved dependencies.

## Calls

- No resolved calls.

## Unresolved References

- dependency-target: NexusReader.Application.Abstractions.Services (interface reference)
- dependency-target: Microsoft.Maui.Storage (Preferences, SecureStorage)
- dependency-target: FluentResults (Result)
- interaction-target: Preferences.Default.Set(key, value)
- interaction-target: Preferences.Default.Get(key, (string?)null)
- interaction-target: Preferences.Default.Set(key, value)
- interaction-target: Preferences.Default.Get(key, defaultValue)
- interaction-target: Preferences.Default.Remove(key)
- interaction-target: await SecureStorage.Default.SetAsync(key, value)
- interaction-target: await SecureStorage.Default.GetAsync(key)
- interaction-target: SecureStorage.Default.Remove(key)

## Coverage

- Symbols: 10
- Executable symbols: 8
- Executable symbols with control flow: 8
- Grounded edges: 10
- Unresolved references: 11
- Control-flow fragments: 8
- Unresolved jumps: 0
- Unsupported constructs: 0
- Control-flow coverage: 100%
- Required diagrams: 2
- Generated diagrams: 10

## Control Flow Fragments

- SaveStringAsync: 7 nodes, 6 edges, 0 jumps, 0 unsupported constructs
- GetStringAsync: 7 nodes, 6 edges, 0 jumps, 0 unsupported constructs
- SaveBoolAsync: 7 nodes, 6 edges, 0 jumps, 0 unsupported constructs
- GetBoolAsync: 7 nodes, 6 edges, 0 jumps, 0 unsupported constructs
- RemoveAsync: 7 nodes, 6 edges, 0 jumps, 0 unsupported constructs
- SaveSecureString: 8 nodes, 7 edges, 0 jumps, 0 unsupported constructs
- GetSecureString: 8 nodes, 7 edges, 0 jumps, 0 unsupported constructs
- RemoveSecureAsync: 7 nodes, 6 edges, 0 jumps, 0 unsupported constructs

## Diagrams

### MauiStorageService Neighborhood

```mermaid
flowchart LR
    class_jm4wx0_mauistorageservice("MauiStorageService")
    file_d17zn6_mauistorageservice_cs("MauiStorageService")
    method_1bfedhw_getsecurestring[["GetSecureString()"]]
    method_1w0f8ik_removeasync[["RemoveAsync()"]]
    method_6i8lek_getstringasync[["GetStringAsync()"]]
    method_ef0iff_saveboolasync[["SaveBoolAsync()"]]
    method_h3fyyz_savesecurestring[["SaveSecureString()"]]
    method_kv7eey_removesecureasync[["RemoveSecureAsync()"]]
    method_rzym3m_getboolasync[["GetBoolAsync()"]]
    method_s95smj_savestringasync[["SaveStringAsync()"]]
    type_1nbofxi_mauistorageservice[/"MauiStorageService"/]
```

### MauiStorageService Execution Overview

```mermaid
flowchart TD
    class_jm4wx0_mauistorageservice("MauiStorageService")
    method_1bfedhw_getsecurestring[["GetSecureString()"]]
    method_1w0f8ik_removeasync[["RemoveAsync()"]]
    method_6i8lek_getstringasync[["GetStringAsync()"]]
    method_ef0iff_saveboolasync[["SaveBoolAsync()"]]
    method_h3fyyz_savesecurestring[["SaveSecureString()"]]
    method_kv7eey_removesecureasync[["RemoveSecureAsync()"]]
    method_rzym3m_getboolasync[["GetBoolAsync()"]]
    method_s95smj_savestringasync[["SaveStringAsync()"]]
    unresolved_unresolved_14jpd1a_interaction_target{"Unresolved: SecureStorage.Default.Remove(key)"}
    unresolved_unresolved_14mo52j_interaction_target{"Unresolved: Preferences.Default.Set(key, value)"}
    unresolved_unresolved_1kr9h8o_interaction_target{"Unresolved: Preferences.Default.Get(key, (string?)null)"}
    unresolved_unresolved_1n470aa_interaction_target{"Unresolved: Preferences.Default.Remove(key)"}
    unresolved_unresolved_1owtkrk_interaction_target{"Unresolved: await SecureStorage.Default.GetAsync(key)"}
    unresolved_unresolved_iaz95s_interaction_target{"Unresolved: Preferences.Default.Get(key, defaultValue)"}
    unresolved_unresolved_kxn7x9_interaction_target{"Unresolved: await SecureStorage.Default.SetAsync(key, value)"}
    class_jm4wx0_mauistorageservice -->|contains| method_1bfedhw_getsecurestring
    class_jm4wx0_mauistorageservice -->|contains| method_1w0f8ik_removeasync
    class_jm4wx0_mauistorageservice -->|contains| method_6i8lek_getstringasync
    class_jm4wx0_mauistorageservice -->|contains| method_ef0iff_saveboolasync
    class_jm4wx0_mauistorageservice -->|contains| method_h3fyyz_savesecurestring
    class_jm4wx0_mauistorageservice -->|contains| method_kv7eey_removesecureasync
    class_jm4wx0_mauistorageservice -->|contains| method_rzym3m_getboolasync
    class_jm4wx0_mauistorageservice -->|contains| method_s95smj_savestringasync
    class_jm4wx0_mauistorageservice -->|unresolved interaction| unresolved_unresolved_14jpd1a_interaction_target
    class_jm4wx0_mauistorageservice -->|unresolved interaction| unresolved_unresolved_14mo52j_interaction_target
    class_jm4wx0_mauistorageservice -->|unresolved interaction| unresolved_unresolved_14mo52j_interaction_target
    class_jm4wx0_mauistorageservice -->|unresolved interaction| unresolved_unresolved_1kr9h8o_interaction_target
    class_jm4wx0_mauistorageservice -->|unresolved interaction| unresolved_unresolved_1n470aa_interaction_target
    class_jm4wx0_mauistorageservice -->|unresolved interaction| unresolved_unresolved_1owtkrk_interaction_target
    class_jm4wx0_mauistorageservice -->|unresolved interaction| unresolved_unresolved_iaz95s_interaction_target
    class_jm4wx0_mauistorageservice -->|unresolved interaction| unresolved_unresolved_kxn7x9_interaction_target
```

### SaveStringAsync() Control Flow

```mermaid
flowchart TD
    method_s95smj_savestringasync__action_12_savestringasync_try_12_0__try("Begins protected execution")
    method_s95smj_savestringasync__action_12_try_catch_12__linear("Handle exceptions and return failure result")
    method_s95smj_savestringasync__action_17_savestringasync_catch_17_2__catch("catch Exception ex")
    method_s95smj_savestringasync__entry(["SaveStringAsync entry"])
    method_s95smj_savestringasync__action_14_external_call_14__linear("Write to Preferences")
    method_s95smj_savestringasync__action_15_savestringasync_return_15_1__return(["Returns result"])
    method_s95smj_savestringasync__action_19_savestringasync_return_19_3__return(["Returns result"])
    method_s95smj_savestringasync__action_12_savestringasync_try_12_0__try -->|next| method_s95smj_savestringasync__action_14_external_call_14__linear
    method_s95smj_savestringasync__action_12_try_catch_12__linear -->|next| method_s95smj_savestringasync__action_12_savestringasync_try_12_0__try
    method_s95smj_savestringasync__action_14_external_call_14__linear -->|return| method_s95smj_savestringasync__action_15_savestringasync_return_15_1__return
    method_s95smj_savestringasync__action_15_savestringasync_return_15_1__return -->|exception| method_s95smj_savestringasync__action_17_savestringasync_catch_17_2__catch
    method_s95smj_savestringasync__action_17_savestringasync_catch_17_2__catch -->|return| method_s95smj_savestringasync__action_19_savestringasync_return_19_3__return
    method_s95smj_savestringasync__entry -->|next| method_s95smj_savestringasync__action_12_try_catch_12__linear
```

### GetStringAsync() Control Flow

```mermaid
flowchart TD
    method_6i8lek_getstringasync__action_25_getstringasync_try_25_0__try("Begins protected execution")
    method_6i8lek_getstringasync__action_25_try_catch_25__linear("Handle exceptions and return failure result")
    method_6i8lek_getstringasync__action_29_getstringasync_catch_29_2__catch("catch Exception ex")
    method_6i8lek_getstringasync__entry(["GetStringAsync entry"])
    method_6i8lek_getstringasync__action_27_external_call_27__linear("Read from Preferences")
    method_6i8lek_getstringasync__action_27_getstringasync_return_27_1__return(["Returns result"])
    method_6i8lek_getstringasync__action_31_getstringasync_return_31_3__return(["Returns result"])
    method_6i8lek_getstringasync__action_25_getstringasync_try_25_0__try -->|return| method_6i8lek_getstringasync__action_27_getstringasync_return_27_1__return
    method_6i8lek_getstringasync__action_25_try_catch_25__linear -->|next| method_6i8lek_getstringasync__action_25_getstringasync_try_25_0__try
    method_6i8lek_getstringasync__action_27_external_call_27__linear -->|exception| method_6i8lek_getstringasync__action_29_getstringasync_catch_29_2__catch
    method_6i8lek_getstringasync__action_27_getstringasync_return_27_1__return -->|next| method_6i8lek_getstringasync__action_27_external_call_27__linear
    method_6i8lek_getstringasync__action_29_getstringasync_catch_29_2__catch -->|return| method_6i8lek_getstringasync__action_31_getstringasync_return_31_3__return
    method_6i8lek_getstringasync__entry -->|next| method_6i8lek_getstringasync__action_25_try_catch_25__linear
```

### SaveBoolAsync() Control Flow

```mermaid
flowchart TD
    method_ef0iff_saveboolasync__action_37_saveboolasync_try_37_0__try("Begins protected execution")
    method_ef0iff_saveboolasync__action_37_try_catch_37__linear("Handle exceptions")
    method_ef0iff_saveboolasync__action_42_saveboolasync_catch_42_2__catch("catch Exception ex")
    method_ef0iff_saveboolasync__entry(["SaveBoolAsync entry"])
    method_ef0iff_saveboolasync__action_39_external_call_39__linear("Write bool to Preferences")
    method_ef0iff_saveboolasync__action_40_saveboolasync_return_40_1__return(["Returns result"])
    method_ef0iff_saveboolasync__action_44_saveboolasync_return_44_3__return(["Returns result"])
    method_ef0iff_saveboolasync__action_37_saveboolasync_try_37_0__try -->|next| method_ef0iff_saveboolasync__action_39_external_call_39__linear
    method_ef0iff_saveboolasync__action_37_try_catch_37__linear -->|next| method_ef0iff_saveboolasync__action_37_saveboolasync_try_37_0__try
    method_ef0iff_saveboolasync__action_39_external_call_39__linear -->|return| method_ef0iff_saveboolasync__action_40_saveboolasync_return_40_1__return
    method_ef0iff_saveboolasync__action_40_saveboolasync_return_40_1__return -->|exception| method_ef0iff_saveboolasync__action_42_saveboolasync_catch_42_2__catch
    method_ef0iff_saveboolasync__action_42_saveboolasync_catch_42_2__catch -->|return| method_ef0iff_saveboolasync__action_44_saveboolasync_return_44_3__return
    method_ef0iff_saveboolasync__entry -->|next| method_ef0iff_saveboolasync__action_37_try_catch_37__linear
```

### GetBoolAsync() Control Flow

```mermaid
flowchart TD
    method_rzym3m_getboolasync__action_50_getboolasync_try_50_0__try("Begins protected execution")
    method_rzym3m_getboolasync__action_50_try_catch_50__linear("Handle exceptions")
    method_rzym3m_getboolasync__action_54_getboolasync_catch_54_2__catch("catch Exception ex")
    method_rzym3m_getboolasync__entry(["GetBoolAsync entry"])
    method_rzym3m_getboolasync__action_52_external_call_52__linear("Read bool from Preferences")
    method_rzym3m_getboolasync__action_52_getboolasync_return_52_1__return(["Returns result"])
    method_rzym3m_getboolasync__action_56_getboolasync_return_56_3__return(["Returns result"])
    method_rzym3m_getboolasync__action_50_getboolasync_try_50_0__try -->|return| method_rzym3m_getboolasync__action_52_getboolasync_return_52_1__return
    method_rzym3m_getboolasync__action_50_try_catch_50__linear -->|next| method_rzym3m_getboolasync__action_50_getboolasync_try_50_0__try
    method_rzym3m_getboolasync__action_52_external_call_52__linear -->|exception| method_rzym3m_getboolasync__action_54_getboolasync_catch_54_2__catch
    method_rzym3m_getboolasync__action_52_getboolasync_return_52_1__return -->|next| method_rzym3m_getboolasync__action_52_external_call_52__linear
    method_rzym3m_getboolasync__action_54_getboolasync_catch_54_2__catch -->|return| method_rzym3m_getboolasync__action_56_getboolasync_return_56_3__return
    method_rzym3m_getboolasync__entry -->|next| method_rzym3m_getboolasync__action_50_try_catch_50__linear
```

### RemoveAsync() Control Flow

```mermaid
flowchart TD
    method_1w0f8ik_removeasync__action_62_removeasync_try_62_0__try("Begins protected execution")
    method_1w0f8ik_removeasync__action_62_try_catch_62__linear("Handle exceptions")
    method_1w0f8ik_removeasync__action_67_removeasync_catch_67_2__catch("catch Exception ex")
    method_1w0f8ik_removeasync__entry(["RemoveAsync entry"])
    method_1w0f8ik_removeasync__action_64_external_call_64__linear("Remove key from Preferences")
    method_1w0f8ik_removeasync__action_65_removeasync_return_65_1__return(["Returns result"])
    method_1w0f8ik_removeasync__action_69_removeasync_return_69_3__return(["Returns result"])
    method_1w0f8ik_removeasync__action_62_removeasync_try_62_0__try -->|next| method_1w0f8ik_removeasync__action_64_external_call_64__linear
    method_1w0f8ik_removeasync__action_62_try_catch_62__linear -->|next| method_1w0f8ik_removeasync__action_62_removeasync_try_62_0__try
    method_1w0f8ik_removeasync__action_64_external_call_64__linear -->|return| method_1w0f8ik_removeasync__action_65_removeasync_return_65_1__return
    method_1w0f8ik_removeasync__action_65_removeasync_return_65_1__return -->|exception| method_1w0f8ik_removeasync__action_67_removeasync_catch_67_2__catch
    method_1w0f8ik_removeasync__action_67_removeasync_catch_67_2__catch -->|return| method_1w0f8ik_removeasync__action_69_removeasync_return_69_3__return
    method_1w0f8ik_removeasync__entry -->|next| method_1w0f8ik_removeasync__action_62_try_catch_62__linear
```

### SaveSecureString() Control Flow

```mermaid
flowchart TD
    method_h3fyyz_savesecurestring__action_75_savesecurestring_try_75_0__try("Begins protected execution")
    method_h3fyyz_savesecurestring__action_75_try_catch_75__linear("Handle exceptions for secure save")
    method_h3fyyz_savesecurestring__action_77_savesecurestring_await_77_1__await[["Waits for async work"]]
    method_h3fyyz_savesecurestring__action_80_savesecurestring_catch_80_3__catch("catch Exception ex")
    method_h3fyyz_savesecurestring__entry(["SaveSecureString entry"])
    method_h3fyyz_savesecurestring__action_77_external_call_77__linear("Write to SecureStorage (async)")
    method_h3fyyz_savesecurestring__action_78_savesecurestring_return_78_2__return(["Returns result"])
    method_h3fyyz_savesecurestring__action_82_savesecurestring_return_82_4__return(["Returns result"])
    method_h3fyyz_savesecurestring__action_75_savesecurestring_try_75_0__try -->|next| method_h3fyyz_savesecurestring__action_77_external_call_77__linear
    method_h3fyyz_savesecurestring__action_75_try_catch_75__linear -->|next| method_h3fyyz_savesecurestring__action_75_savesecurestring_try_75_0__try
    method_h3fyyz_savesecurestring__action_77_external_call_77__linear -->|next| method_h3fyyz_savesecurestring__action_77_savesecurestring_await_77_1__await
    method_h3fyyz_savesecurestring__action_77_savesecurestring_await_77_1__await -->|return| method_h3fyyz_savesecurestring__action_78_savesecurestring_return_78_2__return
    method_h3fyyz_savesecurestring__action_78_savesecurestring_return_78_2__return -->|exception| method_h3fyyz_savesecurestring__action_80_savesecurestring_catch_80_3__catch
    method_h3fyyz_savesecurestring__action_80_savesecurestring_catch_80_3__catch -->|return| method_h3fyyz_savesecurestring__action_82_savesecurestring_return_82_4__return
    method_h3fyyz_savesecurestring__entry -->|next| method_h3fyyz_savesecurestring__action_75_try_catch_75__linear
```

### GetSecureString() Control Flow

```mermaid
flowchart TD
    method_1bfedhw_getsecurestring__action_88_getsecurestring_try_88_0__try("Begins protected execution")
    method_1bfedhw_getsecurestring__action_88_try_catch_88__linear("Handle exceptions for secure read")
    method_1bfedhw_getsecurestring__action_90_getsecurestring_await_90_1__await[["Waits for async work"]]
    method_1bfedhw_getsecurestring__action_92_getsecurestring_catch_92_3__catch("catch Exception ex")
    method_1bfedhw_getsecurestring__entry(["GetSecureString entry"])
    method_1bfedhw_getsecurestring__action_90_external_call_90__linear("Read from SecureStorage (async)")
    method_1bfedhw_getsecurestring__action_90_getsecurestring_return_90_2__return(["Returns result"])
    method_1bfedhw_getsecurestring__action_94_getsecurestring_return_94_4__return(["Returns result"])
    method_1bfedhw_getsecurestring__action_88_getsecurestring_try_88_0__try -->|next| method_1bfedhw_getsecurestring__action_90_getsecurestring_await_90_1__await
    method_1bfedhw_getsecurestring__action_88_try_catch_88__linear -->|next| method_1bfedhw_getsecurestring__action_88_getsecurestring_try_88_0__try
    method_1bfedhw_getsecurestring__action_90_external_call_90__linear -->|exception| method_1bfedhw_getsecurestring__action_92_getsecurestring_catch_92_3__catch
    method_1bfedhw_getsecurestring__action_90_getsecurestring_await_90_1__await -->|return| method_1bfedhw_getsecurestring__action_90_getsecurestring_return_90_2__return
    method_1bfedhw_getsecurestring__action_90_getsecurestring_return_90_2__return -->|next| method_1bfedhw_getsecurestring__action_90_external_call_90__linear
    method_1bfedhw_getsecurestring__action_92_getsecurestring_catch_92_3__catch -->|return| method_1bfedhw_getsecurestring__action_94_getsecurestring_return_94_4__return
    method_1bfedhw_getsecurestring__entry -->|next| method_1bfedhw_getsecurestring__action_88_try_catch_88__linear
```

### RemoveSecureAsync() Control Flow

```mermaid
flowchart TD
    method_kv7eey_removesecureasync__action_100_removesecureasync_try_100_0__try("Begins protected execution")
    method_kv7eey_removesecureasync__action_100_try_catch_100__linear("Handle exceptions")
    method_kv7eey_removesecureasync__action_105_removesecureasync_catch_105_2__catch("catch Exception ex")
    method_kv7eey_removesecureasync__entry(["RemoveSecureAsync entry"])
    method_kv7eey_removesecureasync__action_102_external_call_102__linear("Remove key from SecureStorage")
    method_kv7eey_removesecureasync__action_103_removesecureasync_return_103_1__return(["Returns result"])
    method_kv7eey_removesecureasync__action_107_removesecureasync_return_107_3__return(["Returns result"])
    method_kv7eey_removesecureasync__action_100_removesecureasync_try_100_0__try -->|next| method_kv7eey_removesecureasync__action_102_external_call_102__linear
    method_kv7eey_removesecureasync__action_100_try_catch_100__linear -->|next| method_kv7eey_removesecureasync__action_100_removesecureasync_try_100_0__try
    method_kv7eey_removesecureasync__action_102_external_call_102__linear -->|return| method_kv7eey_removesecureasync__action_103_removesecureasync_return_103_1__return
    method_kv7eey_removesecureasync__action_103_removesecureasync_return_103_1__return -->|exception| method_kv7eey_removesecureasync__action_105_removesecureasync_catch_105_2__catch
    method_kv7eey_removesecureasync__action_105_removesecureasync_catch_105_2__catch -->|return| method_kv7eey_removesecureasync__action_107_removesecureasync_return_107_3__return
    method_kv7eey_removesecureasync__entry -->|next| method_kv7eey_removesecureasync__action_100_try_catch_100__linear
```

## Diagram Validation

- Status: pass
