package ai.pai.lensman.upload;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

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

public class UploadPresenter implements UploadContract.Presenter {

    private UploadContract.View uploadView;
    private ArrayList<SessionBean> sessionList;
    private String lensmanId;
    private int sessionSeq;

    public UploadPresenter(UploadContract.View view,String lensmanId){
        this.uploadView = view;
        this.lensmanId = lensmanId;
    }


    @Override
    public void start() {
        sessionList = DBService.getInstance().getSessionBeanListByDay(getSessionDateInLongFormat());
        if(sessionList.size()==0){
            uploadView.showEmptyView();
        }else{
            uploadView.showSessionViews();
            uploadView.refreshSessionViews(sessionList);
        }
        sessionSeq = sessionList.size();
    }

    @Override
    public void stop() {

    }

    @Override
    public SessionBean createNewSession() {
        SessionBean sessionBean = new SessionBean();
        sessionBean.lensmanId = lensmanId;
        sessionBean.sessionDate=getSessionDateInLongFormat();
        sessionBean.sessionSeq = sessionSeq+1;
        sessionBean.sessionId ="chengzhenyu_test"+sessionBean.sessionSeq;
        sessionList.add(sessionBean);
        return sessionBean;
    }

    private long getSessionDateInLongFormat(){
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String dateStr = format.format(new Date());
        return Long.parseLong(dateStr);
    }
}
