package com.ttstd.controlled.activity.splash;

import android.app.Application;
import android.content.Context;

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

import com.ttstd.controlled.base.mvvm.BaseViewModel;
import com.ttstd.controlled.network.DeviceRepository;

/**
 * 启动页 ViewModel：判断设备是否已激活。
 *
 * 已激活 → 进入 MainActivity；未激活 → 进入 ActivationActivity。
 */
public class SplashViewModel extends BaseViewModel {

    /** true=已激活，进入主页；false=未激活，进入激活页。 */
    private final MutableLiveData<Boolean> activated = new MutableLiveData<>();

    private DeviceRepository repository;

    public LiveData<Boolean> getActivated() {
        return activated;
    }

    public void check(Context context) {
        if (repository == null) {
            repository = new DeviceRepository(context);
        }
        // 本地凭据判断为纯内存/SP 读取，无需网络请求。
        activated.setValue(repository.isActivated());
    }
}
