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 Region30 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<>();
        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));

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

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

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

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

        String runningPrice = array.getJSONObject(5).getString("words");
        if (VoltageLevel.isNumeric(runningPrice)) {
            industrialElecPrice.setRunningPrice(new BigDecimal(runningPrice));
        }


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


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


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

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

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

        String demandPrice = array.getJSONObject(11).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).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 < 2; i++) {
            IndustrialElecPrice industrialElecPrice1 = new IndustrialElecPrice();

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

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

            industrialElecPrice1.setProxyPrice(new BigDecimal(proxyPrice));

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

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

            if (VoltageLevel.isNumeric(runningPrice)) {
                industrialElecPrice1.setRunningPrice(new BigDecimal(runningPrice));
            }

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

//            spikePrice = array.getJSONObject(18+a).getString("words");
//            if (VoltageLevel.isNumeric(spikePrice)) {
//                industrialElecPrice1.setSpikePrice(new BigDecimal(spikePrice));
//            }

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

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

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

            demandPrice = array.getJSONObject(20+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(21+a).getString("words");
            if (VoltageLevel.isNumeric(capacityPrice)) {
                industrialElecPrice1.setCapacityPrice(new BigDecimal(capacityPrice));
            }
            industrialElecPrice1.setCreateTime(new Date());
            a=a+9;
            list.add(industrialElecPrice1);
        }



        IndustrialElecPrice industrialElecPrice2 = new IndustrialElecPrice();
        industrialElecPrice2.setVoltageLevel(VoltageLevel.getVoltageLevel(array.getJSONObject(31).getString("words")));

        String nonTimePrice2 = array.getJSONObject(32).getString("words");
        industrialElecPrice2.setNonTimePrice(new BigDecimal(nonTimePrice2));

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

        String proxyPrice2=array.getJSONObject(33).getString("words");
        industrialElecPrice2.setProxyPrice(new BigDecimal(proxyPrice2));

        industrialElecPrice2.setLineLossPrice(new BigDecimal(lineLossPrice));

        industrialElecPrice2.setTransmissionPrice(new BigDecimal(array.getJSONObject(34).getString("words")));

        if (VoltageLevel.isNumeric(runningPrice)) {
            industrialElecPrice2.setRunningPrice(new BigDecimal(runningPrice));
        }

        industrialElecPrice2.setAddPrice(new BigDecimal(array.getJSONObject(35).getString("words")));


        String peakPrice2 = array.getJSONObject(36).getString("words");
        industrialElecPrice2.setPeakPrice(new BigDecimal(peakPrice2));

        String regularPrice2 = array.getJSONObject(37).getString("words");
        industrialElecPrice2.setRegularPrice(new BigDecimal(regularPrice2));

        String lowValleyPrice2 = array.getJSONObject(38).getString("words");
        industrialElecPrice2.setLowValleyPrice(new BigDecimal(lowValleyPrice2));

        String demandPrice2 = array.getJSONObject(39).getString("words");
        if (VoltageLevel.isNumeric(demandPrice2)) {
            industrialElecPrice2.setDemandPrice(new BigDecimal(demandPrice2));
            industrialElecPrice2.setElectricityType(2);
            industrialElecPrice2.setCustomerType(2);
        }else{
            industrialElecPrice2.setElectricityType(1);
            industrialElecPrice2.setCustomerType(1);
        }

        String capacityPrice2 = array.getJSONObject(40).getString("words");
        if (VoltageLevel.isNumeric(capacityPrice2)) {
            industrialElecPrice2.setCapacityPrice(new BigDecimal(capacityPrice2));
        }

        industrialElecPrice2.setCreateTime(new Date());
        industrialElecPrice2.setRegionId(regionId);
        list.add(industrialElecPrice2);

        int b=0;
        for (int i = 0; i < 3; i++) {
            IndustrialElecPrice industrialElecPrice3 = new IndustrialElecPrice();

            industrialElecPrice3.setVoltageLevel(VoltageLevel.getVoltageLevel(array.getJSONObject(41+b).getString("words")));
            industrialElecPrice3.setRegionId(regionId);

            nonTimePrice = array.getJSONObject(42+b).getString("words");
            industrialElecPrice3.setNonTimePrice(new BigDecimal(nonTimePrice));

            industrialElecPrice3.setProxyPrice(new BigDecimal(proxyPrice2));

            industrialElecPrice3.setSpikePriceInterval(spikePriceInterval);
            industrialElecPrice3.setPeakPriceInterval(peakPriceInterval);
            industrialElecPrice3.setRegularPriceInterval(regularPriceInterval);
            industrialElecPrice3.setLowValleyPriceInterval(lowValleyPriceInterval);
            industrialElecPrice3.setDeepValleyPriceInterval(deepValleyPriceInterval);
            industrialElecPrice3.setExecutionTime(executionTime);
            industrialElecPrice3.setLineLossPrice(new BigDecimal(lineLossPrice));

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

            if (VoltageLevel.isNumeric(runningPrice)) {
                industrialElecPrice3.setRunningPrice(new BigDecimal(runningPrice));
            }

            addPrice = array.getJSONObject(44+b).getString("words");
            industrialElecPrice3.setAddPrice(new BigDecimal(addPrice));


            peakPrice = array.getJSONObject(45+b).getString("words");
            industrialElecPrice3.setPeakPrice(new BigDecimal(peakPrice));

            regularPrice = array.getJSONObject(46+b).getString("words");
            industrialElecPrice3.setRegularPrice(new BigDecimal(regularPrice));

            lowValleyPrice = array.getJSONObject(47+b).getString("words");
            industrialElecPrice3.setLowValleyPrice(new BigDecimal(lowValleyPrice));

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

            capacityPrice = array.getJSONObject(49+a).getString("words");
            if (VoltageLevel.isNumeric(capacityPrice)) {
                industrialElecPrice3.setCapacityPrice(new BigDecimal(capacityPrice));
            }
            industrialElecPrice3.setCreateTime(new Date());
            b=b+9;
            list.add(industrialElecPrice3);
        }
       return list;
    }
}
