package me.mkweb.releasr.service.github.internal

import me.mkweb.releasr.model.dto.github.GitHubUserDto
import me.mkweb.releasr.service.github.GitHubHttpService
import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.HttpHeaders
import kotlin.reflect.KClass
import kotlin.reflect.full.cast

@Suppress("UNCHECKED_CAST")
class MockGitHubHttpService() : GitHubHttpService {
    override fun <R : Any> get(url: String, responseType: ParameterizedTypeReference<R>, additionalHeaders: HttpHeaders): R {
        return when (url) {
            "/user" -> getCurrentUser()
            else -> throw RuntimeException("Your mock seems to be messed up")
        } as R
    }

    override fun <B, R : Any> post(url: String, body: B, responseType: ParameterizedTypeReference<R>, additionalHeaders: HttpHeaders): R {
        throw UnsupportedOperationException("not implemented")
    }

    private fun getCurrentUser(): GitHubUserDto = GitHubUserDto("test", 1, "http://foo.com", "foo@bar.ch", "")
}