package com.sdtool.business.service.mall;

import com.sdtool.common.api.mall.MallApiCallService;
import com.sdtool.common.base.BaseService;
import com.sdtool.common.entity.base.InvokeCallParams;
import com.sdtool.common.entity.base.InvokeCallResult;
import com.sdtool.common.entity.site.ERPTokenUser;
import com.sweetfish.service.Local;
import com.sweetfish.service.RetResult;
import com.sweetfish.util.AnyValue;
import com.sweetfish.util.AutoLoad;
import com.sweetfish.util.ResourceType;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author: xl Created on 2024-06-11
 * @Content:
 */
@AutoLoad(false)
@Local
@ResourceType(MallApiCallService.class)
public class MallApiCallServiceImpl extends BaseService implements MallApiCallService {

    @Override
    public void init(AnyValue config) {
        super.init(config);
    }

    @Override
    public void destroy(AnyValue config) {
        super.destroy(config);
    }

    @Override
    public RetResult<InvokeCallResult> callAPi(InvokeCallParams source, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
        if (source == null) {
            return RetResult.<InvokeCallResult>errorT().retinfo("无效的参数信息");
        }

        if (StringUtils.isEmpty(source.getBusinessMethod())) {
            return RetResult.<InvokeCallResult>errorT().retinfo("无效的参数方法[businessMethod]信息");
        }

        source.setCurrentUser(currentUser);
        source.setDataSourceId(dataSourceId);
        source.setSupplierCode(supplierCode);

        return callScript(source.getBusinessMethod(), source, currentUser, dataSourceId, supplierCode);
    }
}
