package com.sdtool.business.service;

import com.sdtool.common.api.AddressService;
import com.sdtool.common.base.BaseService;
import com.sdtool.common.datas.ERPModule;
import com.sdtool.common.entity.base.ProcessStringItem;
import com.sdtool.common.entity.site.ERPTokenUser;
import com.sdtool.common.entity.system.ParseAreaResult;
import com.sweetfish.service.Local;
import com.sweetfish.service.RetResult;
import com.sweetfish.util.AutoLoad;
import com.sweetfish.util.ResourceType;

import java.util.List;

@AutoLoad(false)
@Local
@ResourceType(AddressService.class)
public class AddressServiceImpl extends BaseService implements AddressService {

    //region 地址解析

    /**
     * 地址解析
     *
     * @param address      地址
     * @param currentUser  操作人
     * @param dataSourceId 分库
     * @param supplierCode 分表
     * @return 地址信息
     */
    public RetResult<List<ParseAreaResult>> parseAddress(String address, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
        return handleScriptList("ParseAddress",
                ERPModule.ADDRESSPARSER, dataSourceId, supplierCode,
                () -> ProcessStringItem.newBuilder()
                        .itemValue(address)
                        .currentUser(currentUser)
                        .dataSourceId(dataSourceId)
                        .supplierCode(supplierCode)
                        .build()
        );
    }

    public RetResult<ParseAreaResult> parseAddressBaidu(String address, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
        return handleScript("ParseAddress_Baidu",
                ERPModule.ADDRESSPARSER, dataSourceId, supplierCode,
                () -> ProcessStringItem.newBuilder()
                        .itemValue(address)
                        .currentUser(currentUser)
                        .dataSourceId(dataSourceId)
                        .supplierCode(supplierCode)
                        .build()
        );
    }

    public RetResult<ProcessStringItem> mapAddressUpdate(ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
        return handleScript("MapAddressUpdate2", ERPModule.ADDRESSPARSER, dataSourceId, supplierCode,
                () -> ProcessStringItem.newBuilder()
                        .itemValue("")
                        .currentUser(currentUser)
                        .dataSourceId(dataSourceId)
                        .supplierCode(supplierCode)
                        .build()
        );
    }

    //endregion
}
