summaryrefslogtreecommitdiff
path: root/Hutch/App/AccountSession.swift
blob: 1918b0a5ef32356c8eae2a13771cb6cd4984ac2e (plain) (blame)
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
import Foundation

struct AccountSession: Sendable {
    let account: AccountEntry
    let user: User
    let client: SRHTClient
    let defaults: UserDefaults
    let systemStatusRepository: SystemStatusRepository

    var id: String {
        account.id
    }
}

enum AccountDefaultsStore {
    private static let suitePrefix = "net.cleberg.Hutch.account"

    static func userDefaults(for accountID: String) -> UserDefaults {
        let suiteName = suiteName(for: accountID)
        return UserDefaults(suiteName: suiteName) ?? .standard
    }

    static func clear(accountID: String) {
        let suiteName = suiteName(for: accountID)
        guard let defaults = UserDefaults(suiteName: suiteName) else { return }
        defaults.removePersistentDomain(forName: suiteName)
    }

    private static func suiteName(for accountID: String) -> String {
        "\(suitePrefix).\(accountID)"
    }
}