import Foundation

public protocol PasswordProviding: Sendable {
    func password(for keychainTag: String) -> String?
}

public struct DefaultPasswordProvider: PasswordProviding {
    private let keychain: any KeychainServicing

    public init(keychain: any KeychainServicing = KeychainService()) {
        self.keychain = keychain
    }

    public func password(for keychainTag: String) -> String? {
        try? keychain.loadPassword(account: keychainTag)
    }
}

public struct StaticPasswordProvider: PasswordProviding {
    private let password: String

    public init(password: String) {
        self.password = password
    }

    public func password(for keychainTag: String) -> String? {
        password
    }
}
