package com.atmob.voiceai.module.history;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;

import com.atmob.app.lib.base.BaseViewModel;
import com.atmob.common.runtime.ActivityUtil;
import com.atmob.voiceai.data.api.bean.UserVoiceBean;
import com.atmob.voiceai.data.repositories.HistoryRepository;
import com.atmob.voiceai.data.repositories.MemberRepository;
import com.atmob.voiceai.module.result.VoiceResultActivity;
import com.atmob.voiceai.module.setting.SettingActivity;
import com.atmob.voiceai.module.subscription.SubscriptionPageActivity;

import java.util.List;

import javax.inject.Inject;

import dagger.hilt.android.lifecycle.HiltViewModel;

@HiltViewModel
public class HistoryViewModel extends BaseViewModel {


    private final HistoryRepository historyRepository;
    private final MemberRepository memberRepository;


    @Inject
    public HistoryViewModel(HistoryRepository historyRepository, MemberRepository memberRepository) {
        this.historyRepository = historyRepository;
        this.memberRepository = memberRepository;
    }

    public boolean isSmoothScrollToTop() {
        return historyRepository.isSmoothScrollToTop();
    }


    public LiveData<List<UserVoiceBean>> getVoiceHistoryList() {
        return historyRepository.getVoiceHistoryList();
    }

    public LiveData<Boolean> isMember() {
        return memberRepository.getIsMember();
    }

    public void onSettingClick() {
        SettingActivity.start(ActivityUtil.getTopActivity());
    }


    public void onGoSubscriptionClick() {
        SubscriptionPageActivity.start(ActivityUtil.getTopActivity());
    }

    public void onHistoryItemClick(@NonNull UserVoiceBean cloneHistoryBean) {
        VoiceResultActivity.start(ActivityUtil.getTopActivity(), cloneHistoryBean);
    }

    public void refreshHistoryList(int page) {
        historyRepository.refreshCloneHistory(page);
    }

    public LiveData<Boolean> getRefreshing() {
        return historyRepository.getRefreshing();
    }
}
