summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadSettings/AccessMethodRepositoryProtocol.swift
blob: d44f009911b4a239dc82c6b3d07db80fbe64c32a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
//  AccessMethodRepositoryProtocol.swift
//  MullvadVPN
//
//  Created by pronebird on 28/11/2023.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Combine
import MullvadTypes

public protocol AccessMethodRepositoryDataSource: Sendable {
    /// Publisher that propagates a snapshot of all access methods upon modifications.
    var accessMethodsPublisher: AnyPublisher<[PersistentAccessMethod], Never> { get }

    /// - Returns: the default strategy.
    var directAccess: PersistentAccessMethod { get }

    /// Fetch all access method from the persistent store.
    /// - Returns: an array of all persistent access method.
    func fetchAll() -> [PersistentAccessMethod]

    /// Save last reachable access method to the persistent store.
    func requestAccessMethod(_ method: PersistentAccessMethod)

    /// Fetch last reachable access method from the persistent store.
    func fetchLastReachable() -> PersistentAccessMethod
}

public protocol AccessMethodRepositoryProtocol: AccessMethodRepositoryDataSource {
    /// Publisher that propagates a snapshot of last reachable access method upon modifications.
    var currentAccessMethodPublisher: AnyPublisher<PersistentAccessMethod, Never> { get }

    /// Add new access method.
    /// - Parameter method: persistent access method model.
    func save(_ method: PersistentAccessMethod, notifyingAPI: Bool)

    /// Delete access method by id.
    /// - Parameter id: an access method id.
    func delete(id: UUID)

    /// Fetch access method by id.
    /// - Parameter id: an access method id.
    /// - Returns: a persistent access method model upon success, otherwise `nil`.
    func fetch(by id: UUID) -> PersistentAccessMethod?

    ///  Refreshes the storage with default values.
    func addDefaultsMethods()
}