package com.oguerreiro.resilient.activities.period;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.oguerreiro.resilient.activity.AbstractTask;
import com.oguerreiro.resilient.activity.ActivityDomain;
import com.oguerreiro.resilient.activity.GenericGuide;
import com.oguerreiro.resilient.activity.GenericResult;
import com.oguerreiro.resilient.activity.WorkResultEnum;
import com.oguerreiro.resilient.service.ResilientLogService;

@Qualifier("myClearResilientLogTask")
@Component
public class ClearResilientLogTaskImpl<AD extends ActivityDomain> extends
    AbstractTask<GenericResult, GenericGuide<AD>, ClearResilientLogTask<AD>> implements ClearResilientLogTask<AD> {

  private final ResilientLogService resilientLogService;

  public ClearResilientLogTaskImpl(ResilientLogService resilientLogService) {
    this.resilientLogService = resilientLogService;
  }

  @Override
  public GenericResult doTask(GenericGuide<AD> guide) {
    ActivityDomain activitydomain = guide.getActivityDomain();

    //Clear logs for the activity domain entity
    resilientLogService.deleteAllByOwnerIdWithNewTransaction(activitydomain.getId());

    return new GenericResult(WorkResultEnum.COMPLETED);
  }

}
