package com.bocloud.ims.service.upgrade.migration.from50to55;

import com.bocloud.common.enums.BoCloudMethod;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.utils.MapTools;
import com.bocloud.ims.service.upgrade.AbstractUpgradeTask;
import com.bocloud.ims.service.upgrade.UpgradeVersion;
import com.bocloud.service.http.core.ServiceFactory;
import com.bocloud.service.http.model.RemoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;

@Component("5.0-5.5-SmsUserTask")
public class SmsUserTask extends AbstractUpgradeTask {


    private final ApplicationContext context;

    @Autowired
    public SmsUserTask(ApplicationContext context) {
        this.context = context;
    }

    @Override
    public UpgradeVersion getUpgradeVersion() {
        return UpgradeVersion.from50to55;
    }

    @Override
    public void run() {
        Map<String, Object> headers = MapTools.simpleMap("Content-Type", "application/json");
        ServiceFactory serviceFactory = context.getBean(ServiceFactory.class);
        RemoteService service = serviceFactory.build(BoCloudService.SMS, "/status", BoCloudMethod.GET, headers, null);
        BocloudResult<?> result = service.invoke();
        Assert.isTrue(result.isSuccess(), result.getMessage());
    }
}
