package ru.myitschool.work.domain.login;

import androidx.annotation.NonNull;

import java.util.function.Consumer;

import ru.myitschool.work.domain.entities.Status;

public class AuthUseCase {
    private final LoginRepository repository;

    public AuthUseCase(LoginRepository repository) {
        this.repository = repository;
    }

    public void execute(@NonNull String auth, @NonNull Consumer<Status<Boolean>> callback) {
        repository.auth(auth, status -> {
            callback.accept(new Status<>(
                    status.getStatusCode(),
                    (status.getStatusCode() == 200 || status.getStatusCode() == 401) ? status.getStatusCode() == 200 : null,
                    status.getErrors()
            ));
        });
    }
}
