package com.atmob.voiceai.module.setting;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.atmob.app.lib.base.BaseViewModel;
import com.atmob.app.lib.livedata.SingleLiveEvent;
import com.atmob.common.runtime.ActivityUtil;
import com.atmob.common.runtime.ContextUtil;
import com.atmob.voiceai.R;
import com.atmob.voiceai.data.consts.Constants;
import com.atmob.voiceai.data.consts.EventId;
import com.atmob.voiceai.data.repositories.MemberRepository;
import com.atmob.voiceai.handlers.EventHandler;
import com.atmob.voiceai.module.subscription.SubscriptionPageActivity;
import com.atmob.voiceai.utils.AppUtil;
import com.atmob.voiceai.utils.CommonUtils;
import com.atmob.voiceai.utils.ScoringUtils;
import com.atmob.voiceai.utils.SystemUtil;
import com.atmob.voiceai.utils.ToastUtil;

import javax.inject.Inject;

import dagger.hilt.android.lifecycle.HiltViewModel;

@HiltViewModel
public class SettingViewModel extends BaseViewModel {


    private final MutableLiveData<Boolean> isHideScoring = new MutableLiveData<>();
    private final SingleLiveEvent<?> showScoringEvent = new SingleLiveEvent<>();
    private final MutableLiveData<String> versionName = new MutableLiveData<>();
    private final MutableLiveData<String> proName = new MutableLiveData<>();
    private final MemberRepository memberRepository;

    @Inject
    public SettingViewModel(MemberRepository memberRepository) {
        this.memberRepository = memberRepository;
        Context context = ContextUtil.getContext();
        versionName.setValue(context.getString(R.string.version_name, SystemUtil.getVersionName(context)));
        proName.setValue(context.getString(R.string.setting_app_name_pro, context.getString(R.string.app_name)));
        isHideScoring.setValue(ScoringUtils.isHideScoring());
    }

    public LiveData<Boolean> getIsHideScoring() {
        return isHideScoring;
    }

    public LiveData<?> getShowScoringEvent() {
        return showScoringEvent;
    }

    public LiveData<String> getProName() {
        return proName;
    }

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

    public LiveData<String> getVersionName() {
        return versionName;
    }


    public void setHideScoring() {
        isHideScoring.setValue(true);
    }

    public void onSettingProClick() {
        EventHandler.report(EventId.settingpro_001);
        SubscriptionPageActivity.start(ActivityUtil.getTopActivity());
    }

    public void onRateClick() {
        EventHandler.report(EventId.settingrateapp_001);
        showScoringEvent.call();
    }


    public void onSendEmailClick() {
        EventHandler.report(EventId.settingcontact_001);
        CommonUtils.sendEmail(ActivityUtil.getTopActivity(), "Voice AI", "", Constants.SEND_EMAIL_ADDRESS);
    }

    public void onPrivacyPolicyClick() {
        CommonUtils.startWeb(Constants.PRIVACY_POLICY);
    }

    public void onTermsOfServiceClick() {
        CommonUtils.startWeb(Constants.USER_AGREEMENT);
    }

}
