package de.avatic.taricdb.service;

import java.util.concurrent.atomic.AtomicReference;

import org.springframework.stereotype.Service;

import de.avatic.taricdb.model.SetupStatus;

@Service
public class SetupStatusService {
	
	AtomicReference<SetupStatus> status = new AtomicReference<SetupStatus>();
	
	private int recordTotalCount = 0;
	
	public void resetOnStartup() {
		recordTotalCount = 0;
		this.status.set(new SetupStatus(0, 0, "Initializing ...", true, null));
		
	}
	
	public void setStatus(int recordCurrentCount, String status, boolean running, String exitStatus) {
		this.status.set(new SetupStatus(recordCurrentCount, recordTotalCount, status, running, exitStatus));
	}
	

	public SetupStatus getLatestStatus() {
		if (status.get() == null) {
			return new SetupStatus(0, 0, "Stand By", false, null);
		}
		return status.get();
	}
	
	public void setTotalRecordCount(int recordTotalCount) {
		this.recordTotalCount = recordTotalCount;
	}
	
	public int getRecordTotalCount() {
		return recordTotalCount;
	}

}
