package com.cool.store.request;

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

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import java.util.Objects;

@Data
public class AddPointDetailRequest {

    @NotBlank
    @ApiModelProperty("铺位名称")
    private String pointName;

    @ApiModelProperty("所属大区")
    private Long regionId;

    @NotBlank
    @ApiModelProperty("经度")
    private String longitude;

    @NotBlank
    @ApiModelProperty("纬度")
    private String latitude;

    @ApiModelProperty("省")
    private String province;

    @ApiModelProperty("市")
    private String city;

    @ApiModelProperty("区/县")
    private String district;

    @ApiModelProperty("街道")
    private String township;

    @NotBlank
    @ApiModelProperty("详细地址")
    private String address;

    @ApiModelProperty("经营状况 1营业中 2空铺")
    private Integer businessStatus;

    @ApiModelProperty("09:00-10:00人流量")
    private Integer nineFlowRate;

    @ApiModelProperty("10:00-11:00人流量")
    private Integer tenFlowRate;

    @ApiModelProperty("18:00-19:00人流量")
    private Integer eighteenFlowRate;

    @ApiModelProperty("19:00-20:00人流量")
    private Integer nineteenFlowRate;

    @Min(1)
    @Max(2)
    @ApiModelProperty("店铺方位 1主要路线, 2次要路线")
    private Integer pointDirection;

    @Min(1)
    @Max(4)
    @ApiModelProperty("立地条件1.单门面 2.双门面 3.多门面 4.转角")
    private Integer siteConditions;

    @ApiModelProperty("使用面积(一楼)")
    private String pointArea;

    @ApiModelProperty("门店内宽")
    private String storeWidth;

    @ApiModelProperty("房东姓名")
    private String landlordUsername;

    @ApiModelProperty("房东电话")
    private String landlordMobile;

    @Min(1)
    @Max(4)
    @ApiModelProperty("支付方式 1.月付 2.季付 3.半年付 4.年付")
    private Integer paymentMethod;

    @Min(1)
    @Max(4)
    @ApiModelProperty("物业状态 1.原始房东 2.二房东 3.三房东 4.招投标性质")
    private Integer propertyStatus;

    @ApiModelProperty("转让费")
    private String transferFee;

    @Min(1)
    @Max(4)
    @ApiModelProperty("覆盖社区 1.800户以下 2.800-1200户 3.1200-2000户 4.2000户以上")
    private Integer coverCommunity;

    @Min(1)
    @Max(4)
    @ApiModelProperty("消费能力 1.高端 2.中高端 3.中端 4.低端")
    private Integer consumerAbility;

    @Min(1)
    @Max(2)
    @ApiModelProperty("聚客点农贸市场 1.是 2.否")
    private Integer gatherGuestFarmerMarket;

    @Min(1)
    @Max(4)
    @ApiModelProperty("聚客点医院 1.甲等医院  2.市级医院  3.县区级医院  4.无医院")
    private Integer gatherGuestHospital;

    @Min(1)
    @Max(4)
    @ApiModelProperty("聚客点学校 1.幼儿园/小学 2.大学/学院 3.初中/高中 4.无学校")
    private Integer gatherGuestSchool;

    @Min(1)
    @Max(2)
    @ApiModelProperty("门店人流动向 1.主要流动路线 2.次要流动路线")
    private Integer storeFlowTrend;

    @Min(1)
    @Max(3)
    @ApiModelProperty("周边100米内餐饮 1.餐饮连锁店或6家以上餐饮店 2.普通餐饮店 3.无餐饮店")
    private Integer nearRepast;

    @Min(1)
    @Max(4)
    @ApiModelProperty("周边100米内小业态邻居 1.小业态品牌店3家以上 2.小业态普通店3家以上 3.普通小业态店3家以下 4.无小业态店")
    private Integer nearNeighbor;

    @Min(1)
    @Max(4)
    @ApiModelProperty("周边100米内竞争对手 1.品牌水果店2家以上 2.品牌水果店1家及以上 3.夫妻水果店1家及以上 4.无水果店")
    private Integer nearCompete;

    @Min(1)
    @Max(3)
    @ApiModelProperty("周边100米内业态经营情况 1.运营状况良好 2.运营状况一般 3.运营状况差")
    private Integer nearBusinessCondition;

    @Min(1)
    @Max(3)
    @ApiModelProperty("所处位置 1.十字路口 2.居民生活中心 3.社区出入口")
    private Integer intendPosition;

    @Min(1)
    @Max(2)
    @ApiModelProperty("绿化带 1.门口无绿化带阻挡 2.门口有绿化带阻挡")
    private Integer greenBelt;

    @Min(1)
    @Max(3)
    @ApiModelProperty("门店观瞻 1.观赡非常好 2.观赡一般 3.观赡差")
    private Integer storeOutlook;

    @Min(1)
    @Max(3)
    @ApiModelProperty("门店来客便利性 1.门口5米有人行横道 2.门口15米有人行横道 3.无人行横道")
    private Integer guestConvenience;

    @Min(1)
    @Max(5)
    @ApiModelProperty("意向门店开间尺寸 1.转角 2.12米以上 3.8-12米 4.4-8米 5.4米以下")
    private Integer wantShopSize;

    @Min(1)
    @Max(4)
    @ApiModelProperty("竞争对手性质 1.连锁店 2.强势单店 3.经营散户 4.小型摊贩")
    private Integer competeType;

    @Min(1)
    @Max(4)
    @ApiModelProperty("竞争对手经营能力 1.非常好 2.好 3.一般 4.差")
    private Integer competeBusinessCapacity;

    @ApiModelProperty("投资总额")
    private String investAmount;

    @ApiModelProperty("预估日商")
    private String dayTrader;

    @ApiModelProperty("理论毛利率")
    private String profitRate;

    @ApiModelProperty("门店月毛利率")
    private String monthProfitRate;

    @ApiModelProperty("品牌使用费率")
    private String brandUseRate;

    @ApiModelProperty("品牌使用费")
    private String brandUseFee;

    @ApiModelProperty("基本人工费用")
    private String staffFee;

    @ApiModelProperty("奖金分红")
    private String bonus;

    @ApiModelProperty("门店月房租")
    private String monthRent;

    @ApiModelProperty("水电物业及其他")
    private String otherFee;

    @ApiModelProperty("净利润")
    private String netProfit;

    @ApiModelProperty("月投资回报率")
    private String monthRateReturn;

    @ApiModelProperty("租赁合同")
    private String rentContract;

    @ApiModelProperty("图片对象")
    private String pictureObj;

    @ApiModelProperty("人流测算 1.>400人/时以上, 2.300～400人/时, 3.200～300人/时, 4.100～200人/时")
    private Integer flowRateCalculate;


    public static PointDetailInfoDO convertDO(AddPointDetailRequest request) {
        PointDetailInfoDO result = new PointDetailInfoDO();
        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(AddPointDetailRequest request) {
        PointInfoDO result = new PointInfoDO();
        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());
                }
            }
        }
        result.setStorageStatus(StorageStatusEnum.NOT_IN_STORAGE.getCode());
        return result;
    }

}