package com.cool.store.request;

import com.cool.store.entity.PointDetailInfoDO;
import com.cool.store.entity.PointInfoDO;
import com.cool.store.utils.GeoMapUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.Objects;

@Data
public class UpdatePointDetailRequest extends AddPointDetailRequest {

    @NotNull
    @ApiModelProperty("点位id")
    private Long pointId;



    public static PointDetailInfoDO convertDO(UpdatePointDetailRequest request) {
        PointDetailInfoDO result = new PointDetailInfoDO();
        result.setPointId(request.getPointId());
        result.setBusinessStatus(request.getBusinessStatus());
        result.setNineFlowRate(request.getNineFlowRate());
        result.setTenFlowRate(request.getTenFlowRate());
        result.setEighteenFlowRate(request.getEighteenFlowRate());
        result.setNineteenFlowRate(request.getNineteenFlowRate());
        result.setPointDirection(request.getPointDirection());
        result.setSiteConditions(request.getSiteConditions());
        result.setStoreWidth(request.getStoreWidth());
        result.setLandlordUsername(request.getLandlordUsername());
        result.setLandlordMobile(request.getLandlordMobile());
        result.setPaymentMethod(request.getPaymentMethod());
        result.setPropertyStatus(request.getPropertyStatus());
        result.setTransferFee(request.getTransferFee());
        result.setCoverCommunity(request.getCoverCommunity());
        result.setConsumerAbility(request.getConsumerAbility());
        result.setGatherGuestFarmerMarket(request.getGatherGuestFarmerMarket());
        result.setGatherGuestHospital(request.getGatherGuestHospital());
        result.setGatherGuestSchool(request.getGatherGuestSchool());
        result.setStoreFlowTrend(request.getStoreFlowTrend());
        result.setNearRepast(request.getNearRepast());
        result.setNearNeighbor(request.getNearNeighbor());
        result.setNearCompete(request.getNearCompete());
        result.setNearBusinessCondition(request.getNearBusinessCondition());
        result.setIntendPosition(request.getIntendPosition());
        result.setGreenBelt(request.getGreenBelt());
        result.setStoreOutlook(request.getStoreOutlook());
        result.setGuestConvenience(request.getGuestConvenience());
        result.setWantShopSize(request.getWantShopSize());
        result.setCompeteType(request.getCompeteType());
        result.setCompeteBusinessCapacity(request.getCompeteBusinessCapacity());
        result.setInvestAmount(request.getInvestAmount());
        result.setDayTrader(request.getDayTrader());
        result.setProfitRate(request.getProfitRate());
        result.setMonthProfitRate(request.getMonthProfitRate());
        result.setBrandUseRate(request.getBrandUseRate());
        result.setBrandUseFee(request.getBrandUseFee());
        result.setStaffFee(request.getStaffFee());
        result.setBonus(request.getBonus());
        result.setMonthRent(request.getMonthRent());
        result.setOtherFee(request.getOtherFee());
        result.setNetProfit(request.getNetProfit());
        result.setMonthRateReturn(request.getMonthRateReturn());
        result.setRentContract(request.getRentContract());
        result.setPictureObj(request.getPictureObj());
        result.setFlowRateCalculate(request.getFlowRateCalculate());
        return result;
    }

    public static PointInfoDO convertPointDO(UpdatePointDetailRequest request) {
        PointInfoDO result = new PointInfoDO();
        result.setId(request.getPointId());
        result.setPointName(request.getPointName());
        result.setRegionId(request.getRegionId());
        result.setPointArea(request.getPointArea());
        result.setLatitude(request.getLatitude());
        result.setLongitude(request.getLongitude());
        result.setAddress(request.getAddress());
        result.setProvince(request.getProvince());
        result.setCity(request.getCity());
        result.setDistrict(request.getDistrict());
        result.setTownship(request.getTownship());
        if(StringUtils.isAnyBlank(result.getProvince(),result.getCity(), result.getDistrict(), result.getTownship())){
            GeoMapUtil.AddressInfo addressInfo = GeoMapUtil.reverseGeoCoding(result.getLatitude(), result.getLongitude());
            if(Objects.nonNull(addressInfo)){
                if(StringUtils.isBlank(result.getProvince())){
                    result.setProvince(addressInfo.getProvince());
                }
                if(StringUtils.isBlank(result.getCity())){
                    result.setCity(addressInfo.getCity());
                }
                if(StringUtils.isBlank(result.getDistrict())){
                    result.setDistrict(addressInfo.getDistrict());
                }
                if(StringUtils.isBlank(result.getTownship())){
                    result.setTownship(addressInfo.getTownship());
                }
            }
        }
        return result;
    }

}