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 Region28 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_start");

        IndustrialElecPrice industrialElecPrice = new IndustrialElecPrice();
        industrialElecPrice.setVoltageLevel(VoltageLevel.getVoltageLevel(array.getJSONObject(0).getString("words")));

        String nonTimePrice = array.getJSONObject(1).getString("words");
        industrialElecPrice.setNonTimePrice(new BigDecimal(nonTimePrice));

        String proxyPrice = array.getJSONObject(2).getString("words");
        industrialElecPrice.setProxyPrice(new BigDecimal(proxyPrice));

        String transmissionPrice = array.getJSONObject(3).getString("words");
        industrialElecPrice.setTransmissionPrice(new BigDecimal(transmissionPrice));

        String lineLossPrice = array.getJSONObject(4).getString("words");
        industrialElecPrice.setLineLossPrice(new BigDecimal(lineLossPrice));

        String runningPrice = array.getJSONObject(5).getString("words");
        industrialElecPrice.setRunningPrice(new BigDecimal(runningPrice));

        String addPrice = array.getJSONObject(6).getString("words");
        industrialElecPrice.setAddPrice(new BigDecimal(addPrice));

        industrialElecPrice.setSpikePriceInterval(spikePriceInterval);
        industrialElecPrice.setPeakPriceInterval(peakPriceInterval);
        industrialElecPrice.setRegularPriceInterval(regularPriceInterval);
        industrialElecPrice.setLowValleyPriceInterval(lowValleyPriceInterval);
        industrialElecPrice.setDeepValleyPriceInterval(deepValleyPriceInterval);
        industrialElecPrice.setExecutionTime(executionTime);

        String peakPrice = array.getJSONObject(7).getString("words");
        if (VoltageLevel.isNumeric(peakPrice)) {
            industrialElecPrice.setPeakPrice(new BigDecimal(peakPrice));
        }


        String regularPrice = array.getJSONObject(8).getString("words");
        if (VoltageLevel.isNumeric(regularPrice)) {
            industrialElecPrice.setRegularPrice(new BigDecimal(regularPrice));
        }

        String lowValleyPrice = array.getJSONObject(9).getString("words");
        if (VoltageLevel.isNumeric(lowValleyPrice)) {
            industrialElecPrice.setLowValleyPrice(new BigDecimal(lowValleyPrice));
        }
        industrialElecPrice.setElectricityType(1);
        industrialElecPrice.setCustomerType(1);
        industrialElecPrice.setCreateTime(new Date());
        industrialElecPrice.setRegionId(regionId);
        list.add(industrialElecPrice);
        int a = 0;
        for (int i = 0; i < 2; i++) {
            IndustrialElecPrice industrialElecPrice1 = new IndustrialElecPrice();

            industrialElecPrice1.setVoltageLevel(VoltageLevel.getVoltageLevel(array.getJSONObject(11 + a).getString("words")));
            industrialElecPrice1.setRegionId(regionId);
            nonTimePrice = array.getJSONObject(12 + a).getString("words");
            industrialElecPrice1.setNonTimePrice(new BigDecimal(nonTimePrice));

            industrialElecPrice1.setProxyPrice(new BigDecimal(proxyPrice));
            industrialElecPrice1.setLineLossPrice(new BigDecimal(lineLossPrice));
            industrialElecPrice1.setRunningPrice(new BigDecimal(runningPrice));
            industrialElecPrice1.setAddPrice(new BigDecimal(addPrice));
            industrialElecPrice1.setSpikePriceInterval(spikePriceInterval);
            industrialElecPrice1.setPeakPriceInterval(peakPriceInterval);
            industrialElecPrice1.setRegularPriceInterval(regularPriceInterval);
            industrialElecPrice1.setLowValleyPriceInterval(lowValleyPriceInterval);
            industrialElecPrice1.setDeepValleyPriceInterval(deepValleyPriceInterval);
            industrialElecPrice1.setExecutionTime(executionTime);

            industrialElecPrice1.setElectricityType(1);
            industrialElecPrice1.setCustomerType(1);

            transmissionPrice = array.getJSONObject(13 + a).getString("words");
            industrialElecPrice1.setTransmissionPrice(new BigDecimal(transmissionPrice));

            peakPrice = array.getJSONObject(14 + a).getString("words");
            if (VoltageLevel.isNumeric(peakPrice)) {
                industrialElecPrice1.setPeakPrice(new BigDecimal(peakPrice));
            }
            regularPrice = array.getJSONObject(15 + a).getString("words");
            if (VoltageLevel.isNumeric(regularPrice)) {
                industrialElecPrice1.setRegularPrice(new BigDecimal(regularPrice));
            }
            lowValleyPrice = array.getJSONObject(16 + a).getString("words");
            if (VoltageLevel.isNumeric(lowValleyPrice)) {
                industrialElecPrice1.setLowValleyPrice(new BigDecimal(lowValleyPrice));
            }
            industrialElecPrice1.setCreateTime(new Date());
            a = a + 6;
            list.add(industrialElecPrice1);
        }

        int b = 0;
        for (int i = 0; i < 4; i++) {
            IndustrialElecPrice industrialElecPrice2 = new IndustrialElecPrice();

            industrialElecPrice2.setVoltageLevel(VoltageLevel.getVoltageLevel(array.getJSONObject(23 + b).getString("words")));
            industrialElecPrice2.setRegionId(regionId);
            nonTimePrice = array.getJSONObject(24 + b).getString("words");
            industrialElecPrice2.setNonTimePrice(new BigDecimal(nonTimePrice));

            industrialElecPrice2.setProxyPrice(new BigDecimal(proxyPrice));
            industrialElecPrice2.setLineLossPrice(new BigDecimal(lineLossPrice));
            industrialElecPrice2.setRunningPrice(new BigDecimal(runningPrice));
            industrialElecPrice2.setAddPrice(new BigDecimal(addPrice));
            industrialElecPrice2.setSpikePriceInterval(spikePriceInterval);
            industrialElecPrice2.setPeakPriceInterval(peakPriceInterval);
            industrialElecPrice2.setRegularPriceInterval(regularPriceInterval);
            industrialElecPrice2.setLowValleyPriceInterval(lowValleyPriceInterval);
            industrialElecPrice2.setDeepValleyPriceInterval(deepValleyPriceInterval);
            industrialElecPrice2.setExecutionTime(executionTime);

            transmissionPrice = array.getJSONObject(25 + b).getString("words");
            industrialElecPrice2.setTransmissionPrice(new BigDecimal(transmissionPrice));

            peakPrice = array.getJSONObject(26 + b).getString("words");
            if (VoltageLevel.isNumeric(peakPrice)) {
                industrialElecPrice2.setPeakPrice(new BigDecimal(peakPrice));
            }
            regularPrice = array.getJSONObject(27 + b).getString("words");
            if (VoltageLevel.isNumeric(regularPrice)) {
                industrialElecPrice2.setRegularPrice(new BigDecimal(regularPrice));
            }
            lowValleyPrice = array.getJSONObject(28 + b).getString("words");
            if (VoltageLevel.isNumeric(lowValleyPrice)) {
                industrialElecPrice2.setLowValleyPrice(new BigDecimal(lowValleyPrice));
            }
            String demandPrice = array.getJSONObject(29+b).getString("words");
            if (VoltageLevel.isNumeric(demandPrice)) {
                industrialElecPrice2.setDemandPrice(new BigDecimal(demandPrice));
                industrialElecPrice2.setElectricityType(2);
                industrialElecPrice2.setCustomerType(2);
            } else {
                industrialElecPrice2.setElectricityType(1);
                industrialElecPrice2.setCustomerType(1);
            }

            String capacityPrice = array.getJSONObject(30+b).getString("words");
            if (VoltageLevel.isNumeric(capacityPrice)) {
                industrialElecPrice2.setCapacityPrice(new BigDecimal(capacityPrice));
            }
            industrialElecPrice2.setCreateTime(new Date());
            b = b + 8;
            list.add(industrialElecPrice2);
        }
        return list;
    }
}
