# P2.1 iOS Batch B - Validation + Delegation Methods

**Purpose:** Second batch of iOS plugin refactoring - methods that validate input then delegate to services  
**Owner:** Development Team  
**Created:** 2025-12-23  
**Status:** ready  
**Baseline:** See `docs/progress/00-STATUS.md` (v1.0.11-p3-complete)

---

## Goal

Refactor iOS plugin methods that **validate input** then delegate to services. These methods:
- Extract and validate parameters from `CAPPluginCall`
- Handle error responses for invalid input
- Delegate validated parameters to service methods
- Map service results/errors to plugin responses

**Success Criteria:**
- Plugin method validates input, delegates to service
- Service method handles business logic
- External API unchanged
- Tests pass

---

## Target Methods (Batch B)

### Permissions (4 methods)

1. **`checkPermissionStatus()`**
   - Validate: None (read-only)
   - Delegate: `UNUserNotificationCenter.getNotificationSettings()` → parse and format
   - Type: validation (parse settings, format response)

2. **`requestNotificationPermissions()`**
   - Validate: None (request only)
   - Delegate: `UNUserNotificationCenter.requestAuthorization(...)`
   - Type: validation (handle async result)

3. **`getNotificationPermissionStatus()`**
   - Validate: None (read-only)
   - Delegate: `UNUserNotificationCenter.getNotificationSettings()` → parse and format
   - Type: validation (parse settings, format response)

4. **`requestNotificationPermission()`**
   - Validate: None (request only)
   - Delegate: `UNUserNotificationCenter.requestAuthorization(...)`
   - Type: validation (handle async result)

### Scheduling (5 methods)

5. **`scheduleContentFetch()`**
   - Validate: Config object required
   - Delegate: `DailyNotificationScheduler.scheduleFetch(...)` or `DailyNotificationBackgroundTaskManager.scheduleFetch(...)`
   - Type: validation (validate config, delegate)

6. **`scheduleUserNotification()`**
   - Validate: Config object required
   - Delegate: `DailyNotificationScheduler.scheduleUserNotification(...)`
   - Type: validation (validate config, delegate)

7. **`scheduleDailyNotification()`**
   - Validate: Time format (HH:mm), required parameters
   - Delegate: `DailyNotificationScheduler.schedule(...)`
   - Type: validation (validate time format, delegate)

8. **`scheduleDailyReminder()`**
   - Validate: id, title, body, time required; time format (HH:mm)
   - Delegate: `DailyNotificationStorage.storeReminder(...)` + schedule notification
   - Type: validation (validate input, delegate)

9. **`updateDailyReminder()`**
   - Validate: reminderId required
   - Delegate: `DailyNotificationStorage.updateReminder(...)`
   - Type: validation (validate input, delegate)

10. **`cancelDailyReminder()`**
    - Validate: reminderId required
    - Delegate: `DailyNotificationStorage.removeReminder(id)`
    - Type: validation (validate input, delegate)

### Content & History (1 method)

11. **`getPendingNotifications()`**
    - Validate: None (read-only)
    - Delegate: `UNUserNotificationCenter.getPendingNotificationRequests()` → parse and format
    - Type: validation (parse requests, format response)

### Settings & Channels (5 methods)

12. **`isChannelEnabled()`**
    - Validate: channelId (optional)
    - Delegate: `UNUserNotificationCenter.getNotificationSettings()` → check channel
    - Type: validation (parse settings, check channel)

13. **`openChannelSettings()`**
    - Validate: channelId (optional)
    - Delegate: `UIApplication.openSettingsURLString` (with channel fallback)
    - Type: validation (needs app context)

14. **`openNotificationSettings()`**
    - Validate: None
    - Delegate: `UIApplication.openSettingsURLString`
    - Type: validation (needs app context)

15. **`openBackgroundAppRefreshSettings()`**
    - Validate: None
    - Delegate: `UIApplication.openSettingsURLString`
    - Type: validation (needs app context)

16. **`updateSettings()`**
    - Validate: Settings object
    - Delegate: `DailyNotificationStorage.updateSettings(...)` or `DailyNotificationStateActor.saveSettings(...)`
    - Type: validation (validate input, delegate)

### Configuration (1 method)

17. **`configure()`**
    - Validate: Optional parameters (dbPath, storage, ttlSeconds, etc.)
    - Delegate: `DailyNotificationStorage.configure(...)` or reinitialize storage
    - Type: validation (validate input, delegate)

---

## Implementation Strategy

1. **Read current implementation** of each method
2. **Extract validation logic** to plugin method (parameter extraction, format validation)
3. **Identify service method** to delegate to (or create if needed)
4. **Refactor plugin method** to: validate → delegate → map response
5. **Test** that external API behavior is unchanged
6. **Commit** in small batches (2-3 methods per commit)

---

## Service Methods Needed

Some service methods may need to be created or enhanced:
- `DailyNotificationStorage.storeReminder(...)` - May need to be created
- `DailyNotificationStorage.updateReminder(...)` - May need to be created
- `DailyNotificationStorage.removeReminder(id)` - May need to be created
- `DailyNotificationScheduler.scheduleFetch(...)` - Check if exists
- `DailyNotificationScheduler.scheduleUserNotification(...)` - Check if exists

---

## Notes

- iOS uses `CAPPluginCall` for parameter extraction (similar to Android's `PluginCall`)
- Error handling uses `call.reject(message, code)` with `DailyNotificationErrorCodes`
- Async operations use `Task { }` blocks with `await`
- Settings methods need `UIApplication` access (may need activity/view controller)
- Permission methods use `UNUserNotificationCenter` directly (no service wrapper needed)

---

## Estimated Impact

- **Methods refactored:** 17
- **Lines removed:** ~400-500 lines (validation logic moved to services where appropriate)
- **Complexity reduction:** Medium (validation stays in plugin, business logic moves to services)
- **Risk:** Low-Medium (validation logic changes, but external API unchanged)

---

## Next Batch

After Batch B, proceed to **Batch C** (glue/orchestration methods) for complex methods that combine multiple services.

