package com.example.quiz.viewModel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel;

import com.example.quiz.data.model.Pari;
import com.example.quiz.data.repository.PariRepository;
import com.example.quiz.utils.Result;

import java.util.List;

import javax.inject.Inject;

import dagger.hilt.android.lifecycle.HiltViewModel;

@HiltViewModel
public class PariViewModel extends ViewModel {
    private final PariRepository pariRepository;
    private LiveData<Result<Pari>> pari;

    private LiveData<Result<List<Pari>>> derniersParis;

    private LiveData<Result<Pari>> pariAnnule;

    private LiveData<Result<Double>> solde;

    private LiveData<Result<Double>> soldeByDay;

    @Inject
    public PariViewModel(PariRepository repository){
        this.pariRepository = repository;
    }

    public LiveData<Result<Pari>> createPari(Pari pari){
        if(this.pari == null){
            this.pari = pariRepository.createPari(pari);
        }
        return this.pari;
    }

    public LiveData<Result<List<Pari>>> getDerniersParis(String createdBy){
        if(derniersParis == null){
            derniersParis = pariRepository.derniersParis(createdBy);
        }
        return pariRepository.derniersParis(createdBy);
    }

    public LiveData<Result<Pari>> annulerPari(String numeroTicket){
        if(pariAnnule == null){
            pariAnnule = pariRepository.annulerPari(numeroTicket);
        }
        return pariAnnule;
    }

    public LiveData<Result<Double>> getSoldeByCourse(String createdBy, String courseId){
        if(solde == null){
            solde = pariRepository.getSoldeByCourse(createdBy, courseId);
        }
        return solde;
    }

    public LiveData<Result<Double>> getSoldeByDay(String createdBy, String day){
        if(soldeByDay == null){
            soldeByDay = pariRepository.getSoldeByDay(createdBy, day);
        }
        return soldeByDay;
    }
}
