40 lines
1,007 B
Swift
40 lines
1,007 B
Swift
//
|
|
// PersistenceService.swift
|
|
// LuminateCore
|
|
//
|
|
// Created by Brendan Szymanski on 6/10/26.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public struct AuthData: Codable, Sendable {
|
|
public let serverURL: String
|
|
public let token: String
|
|
public let userId: String
|
|
public let username: String
|
|
|
|
public init(serverURL: String, token: String, userId: String, username: String) {
|
|
self.serverURL = serverURL
|
|
self.token = token
|
|
self.userId = userId
|
|
self.username = username
|
|
}
|
|
}
|
|
|
|
public enum PersistenceError: Error {
|
|
case migrationFailed(Error)
|
|
case ioFailed(Error)
|
|
case encodingFailed
|
|
case decodingFailed
|
|
case notFound
|
|
}
|
|
|
|
public protocol PersistenceService: Sendable {
|
|
func loadAuth() async throws -> AuthData
|
|
func saveAuth(_ auth: AuthData) async throws
|
|
func clearAuth() async throws
|
|
|
|
func getPreference(key: String) async throws -> String?
|
|
func setPreference(key: String, value: String) async throws
|
|
func clearAll() async throws
|
|
}
|