package com.shaarit.domain.usecase import com.shaarit.domain.model.Credentials import com.shaarit.domain.repository.AuthRepository import javax.inject.Inject class LoginUseCase @Inject constructor(private val repository: AuthRepository) { suspend operator fun invoke(url: String, secret: String): Result { // Trim so a trailing space from copy/paste or autocomplete does not silently // corrupt the URL or the HMAC key (which would surface as an obscure HTTP 401). val cleanUrl = url.trim() val cleanSecret = secret.trim() if (cleanUrl.isBlank() || cleanSecret.isBlank()) { return Result.failure(IllegalArgumentException("URL and Secret cannot be empty")) } return repository.login(Credentials(cleanUrl, cleanSecret), cleanUrl) } }