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 Region22 implements Region {

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

        JSONObject jsonObject = array.getJSONObject(array.size() - 1);
        Integer rowStart = jsonObject.getInteger("row_start");

        List<IndustrialElecPrice> list = new ArrayList<>();

        String proxyPrice = array.getJSONObject(2).getString("words");
        String lineLossPrice = array.getJSONObject(3).getString("words");

        IndustrialElecPrice industrialElecPrice = new IndustrialElecPrice();

        industrialElecPrice.setLineLossPrice(new BigDecimal(lineLossPrice));

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

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

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

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

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

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

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


        String peakPrice = array.getJSONObject(7).getString("words");
        industrialElecPrice.setPeakPrice(new BigDecimal(peakPrice));

        String regularPrice = array.getJSONObject(8).getString("words");
        industrialElecPrice.setRegularPrice(new BigDecimal(regularPrice));

        String lowValleyPrice = array.getJSONObject(9).getString("words");
        industrialElecPrice.setLowValleyPrice(new BigDecimal(lowValleyPrice));

        String demandPrice = array.getJSONObject(10).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(11).getString("words");
        if (VoltageLevel.isNumeric(capacityPrice)) {
            industrialElecPrice.setCapacityPrice(new BigDecimal(capacityPrice));
        }

        industrialElecPrice.setCreateTime(new Date());
        industrialElecPrice.setRegionId(regionId);
        list.add(industrialElecPrice);
        int a = 0;
        for (int i = 0; i < rowStart; i++) {
            IndustrialElecPrice industrialElecPrice1 = new IndustrialElecPrice();

            industrialElecPrice1.setVoltageLevel(VoltageLevel.getVoltageLevel(array.getJSONObject(12 + a).getString("words")));
            industrialElecPrice1.setRegionId(regionId);

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

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

            industrialElecPrice1.setProxyPrice(new BigDecimal(proxyPrice));
            industrialElecPrice1.setLineLossPrice(new BigDecimal(lineLossPrice));

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

            industrialElecPrice1.setRunningPrice(new BigDecimal(runningPrice));

            industrialElecPrice1.setAddPrice(new BigDecimal(addPrice));

            peakPrice = array.getJSONObject(15 + a).getString("words");
            industrialElecPrice1.setPeakPrice(new BigDecimal(peakPrice));

            regularPrice = array.getJSONObject(16 + a).getString("words");
            industrialElecPrice1.setRegularPrice(new BigDecimal(regularPrice));

            lowValleyPrice = array.getJSONObject(17 + a).getString("words");
            industrialElecPrice1.setLowValleyPrice(new BigDecimal(lowValleyPrice));

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

            capacityPrice = array.getJSONObject(19 + a).getString("words");
            if (VoltageLevel.isNumeric(capacityPrice)) {
                industrialElecPrice1.setCapacityPrice(new BigDecimal(capacityPrice));
            }
            industrialElecPrice1.setCreateTime(new Date());
            a = a + 8;
            list.add(industrialElecPrice1);
        }
        return list;
    }
}

