package com.bocloud.ims.service.internal;

import com.bocloud.common.enums.BoCloudMethod;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.BocloudToken;
import com.bocloud.service.core.CurrentService;
import com.bocloud.service.http.core.ServiceFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class BmsInternalService implements InitializingBean {

    private final Map<String, Object> headers = new HashMap<>(2);

    @Autowired
    private ServiceFactory serviceFactory;
    @Autowired
    private CurrentService currentService;

    public BocloudResult serverRemove(Long id) {
        return serviceFactory.build(BoCloudService.BMS, "/v1/hosts/" + id, BoCloudMethod.DELETE, headers, null).invoke();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        this.headers.put(BocloudToken.INTERNAL_TOKEN, currentService.getToken());
        this.headers.put("source", currentService.getService().getName());
    }
}
