package com.ho.business.util.region;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ho.business.entity.IndustrialElecPrice;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Region3 implements  Region{

    public  List<IndustrialElecPrice> getList(JSONArray array,Integer regionId, String spikePriceInterval, String peakPriceInterval, String regularPriceInterval, String lowValleyPriceInterval, String deepValleyPriceInterval,String executionTime) {

        List<IndustrialElecPrice> list = new ArrayList<>();
        JSONObject jsonObject = array.getJSONObject(array.size() - 1);
        Integer rowStart = jsonObject.getInteger("row_end");
        int a = 0;
        for (int i = 0; i < rowStart; i++) {
            IndustrialElecPrice industrialElecPrice = new IndustrialElecPrice();

            industrialElecPrice.setVoltageLevel(VoltageLevel.getVoltageLevel(array.getJSONObject(0+a).getString("words")));

            String nonTimePrice = array.getJSONObject(1 + a).getString("words");
            if (VoltageLevel.isNumeric(nonTimePrice)) {
                if(regionId.equals(3)){
                    industrialElecPrice.setNonTimePrice(new BigDecimal(nonTimePrice));
                }else{
                    industrialElecPrice.setNonTimePrice(new BigDecimal(nonTimePrice).divide(new BigDecimal(100)));
                }

            }
            industrialElecPrice.setSpikePriceInterval(spikePriceInterval);
            industrialElecPrice.setPeakPriceInterval(peakPriceInterval);
            industrialElecPrice.setRegularPriceInterval(regularPriceInterval);
            industrialElecPrice.setLowValleyPriceInterval(lowValleyPriceInterval);
            industrialElecPrice.setDeepValleyPriceInterval(deepValleyPriceInterval);
            industrialElecPrice.setExecutionTime(executionTime);
            industrialElecPrice.setRegionId(regionId);
            String proxyPrice = array.getJSONObject(2 + a).getString("words");
            if (VoltageLevel.isNumeric(proxyPrice)) {
                if(regionId.equals(3)){
                    industrialElecPrice.setProxyPrice(new BigDecimal(proxyPrice));
                }else{
                    industrialElecPrice.setProxyPrice(new BigDecimal(proxyPrice).divide(new BigDecimal(100)));
                }

            }

            String lineLossPrice = array.getJSONObject(3 + a).getString("words");
            if (VoltageLevel.isNumeric(lineLossPrice)) {
                if(regionId.equals(3)){
                    industrialElecPrice.setLineLossPrice(new BigDecimal(lineLossPrice));
                }else{
                    industrialElecPrice.setLineLossPrice(new BigDecimal(lineLossPrice).divide(new BigDecimal(100)));
                }
            }

            String transmissionPrice = array.getJSONObject(4 + a).getString("words");
            if (VoltageLevel.isNumeric(transmissionPrice)) {
                if(regionId.equals(3)){
                    industrialElecPrice.setTransmissionPrice(new BigDecimal(transmissionPrice));
                }else{
                    industrialElecPrice.setTransmissionPrice(new BigDecimal(transmissionPrice).divide(new BigDecimal(100)));
                }
            }

            String runningPrice = array.getJSONObject(5 + a).getString("words");
            if (VoltageLevel.isNumeric(runningPrice)) {
                if(regionId.equals(3)){
                    industrialElecPrice.setRunningPrice(new BigDecimal(runningPrice));
                }else{
                    industrialElecPrice.setRunningPrice(new BigDecimal(runningPrice).divide(new BigDecimal(100)));
                }
            }

            String addPrice = array.getJSONObject(6 + a).getString("words");
            if (VoltageLevel.isNumeric(addPrice)) {
                if(regionId.equals(3)){
                    industrialElecPrice.setAddPrice(new BigDecimal(addPrice));
                }else{
                    industrialElecPrice.setAddPrice(new BigDecimal(addPrice).divide(new BigDecimal(100)));
                }
            }

            String spikePrice = array.getJSONObject(7 + a).getString("words");
            if (VoltageLevel.isNumeric(spikePrice)) {
                if(regionId.equals(3)){
                    industrialElecPrice.setSpikePrice(new BigDecimal(spikePrice));
                }else{
                    industrialElecPrice.setSpikePrice(new BigDecimal(spikePrice).divide(new BigDecimal(100)));
                }
            }

            String peakPrice = array.getJSONObject(8 + a).getString("words");
            if (VoltageLevel.isNumeric(peakPrice)) {
                if(regionId.equals(3)){
                    industrialElecPrice.setPeakPrice(new BigDecimal(peakPrice));
                }else{
                    industrialElecPrice.setPeakPrice(new BigDecimal(peakPrice).divide(new BigDecimal(100)));
                }
            }

            String regularPrice = array.getJSONObject(9 + a).getString("words");
            if (VoltageLevel.isNumeric(regularPrice)) {
                if(regionId.equals(3)){
                    industrialElecPrice.setRegularPrice(new BigDecimal(regularPrice));
                }else{
                    industrialElecPrice.setRegularPrice(new BigDecimal(regularPrice).divide(new BigDecimal(100)));
                }
            }

            String lowValleyPrice = array.getJSONObject(10 + a).getString("words");
            if (VoltageLevel.isNumeric(lowValleyPrice)) {
                if(regionId.equals(3)){
                    industrialElecPrice.setLowValleyPrice(new BigDecimal(lowValleyPrice));
                }else{
                    industrialElecPrice.setLowValleyPrice(new BigDecimal(lowValleyPrice).divide(new BigDecimal(100)));
                }
            }

            String demandPrice = array.getJSONObject(11 + a).getString("words");
            if (VoltageLevel.isNumeric(demandPrice)) {
                industrialElecPrice.setDemandPrice(new BigDecimal(demandPrice));
                industrialElecPrice.setElectricityType(2);
                industrialElecPrice.setCustomerType(2);
            }else {
                industrialElecPrice.setElectricityType(1);
                industrialElecPrice.setCustomerType(1);
            }

            String capacityPrice = array.getJSONObject(12 + a).getString("words");
            if (VoltageLevel.isNumeric(capacityPrice)) {
                industrialElecPrice.setCapacityPrice(new BigDecimal(capacityPrice));
            }
            industrialElecPrice.setCreateTime(new Date());
            a = a + 13;
            list.add(industrialElecPrice);
        }
        return list;
    }
}
