package com.tencent.liteav.demo.superplayer.database;

import android.app.Application;

import androidx.annotation.NonNull;

import com.tencent.liteav.demo.superplayer.database.PlayerDatabase;
import com.tencent.liteav.demo.superplayer.database.PlayerDatabaseProvider;
import com.tencent.liteav.demo.superplayer.database.repo.PlayerRepository;

public class PlayerApplication extends Application implements PlayerDatabaseProvider {
    private PlayerDatabase database;
    private PlayerRepository repository;

    @NonNull
    @Override
    public PlayerDatabase getPlayerDatabase() {
        if (database == null) {
            database = PlayerDatabase.Companion.getDatabase(this);
        }

        return database;
    }


    @NonNull
    @Override
    public PlayerRepository getPlayerRepository() {
        if (repository == null) {
            repository = new PlayerRepository(
                    getPlayerDatabase().historyDao(),
                    getPlayerDatabase().countDownDao()
            );
        }
        return repository;
    }
}
