package com.oguerreiro.resilient.activities.inputDataImporter;

import org.springframework.stereotype.Component;

import com.oguerreiro.resilient.activity.AbstractTask;
import com.oguerreiro.resilient.activity.GenericGuide;
import com.oguerreiro.resilient.activity.GenericResult;
import com.oguerreiro.resilient.activity.WorkResultEnum;
import com.oguerreiro.resilient.domain.InputDataUpload;
import com.oguerreiro.resilient.service.InputDataService;

@Component
public class ClearInputDataTaskImpl extends
    AbstractTask<GenericResult, GenericGuide<InputDataUpload>, ClearInputDataTask> implements ClearInputDataTask {

  private final InputDataService inputDataService;

  public ClearInputDataTaskImpl(InputDataService inputDataService) {
    this.inputDataService = inputDataService;
  }

  @Override
  public GenericResult doTask(GenericGuide<InputDataUpload> guide) {
    InputDataUpload inputDataUpload = guide.getActivityDomain();

    // Clear previously imported InputData.
    this.inputDataService.deleteAllInputDataFromDatafileInNewTransaction(inputDataUpload.getOwner(),
        inputDataUpload.getPeriod(), inputDataUpload.getType());

    return new GenericResult(WorkResultEnum.COMPLETED);
  }

}
