Version Catalogs

Version Catalogs

in
Table of contents

Heading 1

Heading 2

Heading 3

EN

package com.javiersc.marvelApp.app.data.useCasesImpl

import cc.popkorn.annotations.Injectable
import cc.popkorn.core.Scope
import com.javiersc.either.network.resource.toResourceSimple
import com.javiersc.either.resource.ResourceEither
import com.javiersc.marvelApp.app.data.network.models.CharacterWrapperDTO
import com.javiersc.marvelApp.app.data.network.models.toCharacters
import com.javiersc.marvelApp.app.data.network.services.CharactersService
import com.javiersc.marvelApp.app.domain.models.Character
import com.javiersc.marvelApp.app.domain.models.DefaultError
import com.javiersc.marvelApp.app.domain.useCases.GetCharacters

@Injectable(scope = Scope.BY_USE)
class GetCharactersImpl(private val charactersService: CharactersService) : GetCharacters {

    val name: String = "Spider-man"
    val age: Int = 19
    val hasCar: Boolean = false

    override suspend fun invoke(name: String?): ResourceEither<DefaultError, List<Character>> =
        charactersService
            .getCharacters(name)
            .toResourceSimple(
                success = CharacterWrapperDTO::toCharacters,
                httpError = { DefaultError.Unknown },
                localError = { DefaultError.NoInternet },
                remoteError = { DefaultError.Unknown },
                unknownError = { DefaultError.Unknown },
            )
}