package com.sunyard.chsm.sdf.adapter;

import com.sunyard.chsm.enums.ManufacturerModelEnum;
import com.sunyard.chsm.sdf.context.DeviceContext;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.util.Assert;

import java.util.Objects;

/**
 * @author liulu
 * @since 2024/11/5
 */
public class SdfApiAdapterFactory {


    public static SdfApiAdapter newInstance(DeviceContext device) {

        Assert.hasText(device.getManufacturerModel(), "设备型号不能为空");
        ManufacturerModelEnum model = ManufacturerModelEnum.of(device.getManufacturerModel());

        if (Objects.isNull(model) && Objects.equals(BouncyCastleProvider.PROVIDER_NAME, device.getManufacturerModel())) {
            // bc adaptor
            return new BcSdfApiAdaptor();
        }
        switch (model) {
            case enc001:
                return new SunyardJnaSdfAdaptor(device.getServiceIp(), device.getServicePort());
            default:
                throw new UnsupportedOperationException("不支持的设备型号: " + device.getManufacturerModel());
        }
    }


}
