package cc.smtweb.framework.core.mvc.scheduler;

import cc.smtweb.framework.core.mvc.controller.access.MethodAccess;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class AbstractJob {
    final MethodAccess method;
    @Getter
    private String key;
    boolean hasPointParam;
//  @Getter @Setter
//  private AbstractJobQueue jobQueue;

    public AbstractJob(MethodAccess methodAccess) {
        this.method = methodAccess;
        this.hasPointParam = methodAccess.findParam(SchedulerPoint.class) != null;
    }

    protected void initKey(String key) {
        this.key = key;
    }

//  public void invoke(Map<String, Object> params) {
//    try {
//      // 组织断点对象参数
//      Map<String, Object> params = null;
//      SchedulerPoint schedulerPoint = null;
//      if (hasPointParam) {
//        schedulerPoint = jobManager.loadBreakPoint(this);
//        if (schedulerPoint != null) {
//          params = new HashMap<>(1);
//          params.put(SchedulerPoint.class.getName(), schedulerPoint);
//        }
//      }
//
//      method.invoke(beanContext, params, null, null, null);
//
//      if (hasPointParam) {
//        jobManager.saveBreakPoint(this, schedulerPoint);
//      }
//    } catch (InvocationTargetException e) {
//      if (e.getCause() != null) {
//        log.error(e.getCause().getMessage(), e.getCause());
//      } else {
//        log.error(e.getMessage(), e);
//      }
//    } catch (Exception e) {
//      log.error(e.getMessage(), e);
//    }
//  }

    public abstract AbstractJobQueue createJobQueue(AbstractJobExecutor jobManager);

    public String getName() {
        return this.method.fullName();
    }
}
