package ai.pai.lensman.session;

import java.util.ArrayList;

import ai.pai.lensman.bean.PhotoBean;
import ai.pai.lensman.bean.SessionBean;
import ai.pai.lensman.db.DBService;

public class SessionPresenter implements SessionContract.Presenter,SessionInteractor.SessionListener{

    private SessionInteractor interactor;
    private ArrayList<PhotoBean> photoList;
    private SessionContract.View sessionView;

    public SessionPresenter(SessionBean sessionBean, SessionContract.View view){
        this.sessionView = view;
        photoList = DBService.getInstance().getPhotoListBySessionId(sessionBean.sessionId);
        interactor = new SessionInteractor(sessionBean,this);
    }

    @Override
    public void start() {
        if(photoList.size()==0){
            sessionView.showEmptyView();
        }else{
            sessionView.showPhotoRecyclerView();
        }
        interactor.startSession();
    }

    @Override
    public void stop() {
        interactor.endSession();
    }

    @Override
    public void onSessionStartSuccess(String session) {
        sessionView.showToast("session启动成功");
    }

    @Override
    public void onSessionStartError(String session) {
        sessionView.showToast("session启动失败");
    }

    @Override
    public void onSessionPhotoCaptured(final PhotoBean bean) {
        DBService.getInstance().addPhotoBean(bean);
        sessionView.showPhotoRecyclerView();
        sessionView.addNewPhoto(bean);
    }

    @Override
    public void onSessionEnd(String session) {

    }
}
