package com.oguerreiro.resilient.activities.inputDataImporter;

import org.springframework.beans.factory.annotation.Qualifier;
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.InputDataUploadLogService;

@Qualifier("myClearInputDataUploadLogTask")
@Component
public class ClearInputDataUploadLogTaskImpl
    extends AbstractTask<GenericResult, GenericGuide<InputDataUpload>, ClearInputDataUploadLogTask>
    implements ClearInputDataUploadLogTask {

  private final InputDataUploadLogService inputDataUploadLogService;

  public ClearInputDataUploadLogTaskImpl(InputDataUploadLogService inputDataUploadLogService) {
    this.inputDataUploadLogService = inputDataUploadLogService;
  }

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

    //Clear logs for InputdataUpload entity
    inputDataUploadLogService.deleteAllByInputDataUploadWithNewTransaction(inputDataUpload);

    return new GenericResult(WorkResultEnum.COMPLETED);
  }

}
