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 Region1 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");
        String feedPeakPrice=array.getJSONObject(1).getString("words");
        String feedRegularPrice=array.getJSONObject(2).getString("words");
        String feedLowValleyPrice=array.getJSONObject(3).getString("words");
        String linePeakPrice=array.getJSONObject(4).getString("words");
        String lineRegularPrice=array.getJSONObject(5).getString("words");
        String lineLowValleyPrice=array.getJSONObject(6).getString("words");
        String runningPrice=array.getJSONObject(8).getString("words");
        String addPrice=array.getJSONObject(9).getString("words");

        IndustrialElecPrice industrialElecPrice = new IndustrialElecPrice();
        industrialElecPrice.setFeedPeakPrice(new BigDecimal(feedPeakPrice));
        industrialElecPrice.setFeedRegularPrice(new BigDecimal(feedRegularPrice));
        industrialElecPrice.setFeedLowValleyPrice(new BigDecimal(feedLowValleyPrice));
        industrialElecPrice.setLinePeakPrice(new BigDecimal(linePeakPrice));
        industrialElecPrice.setLineRegularPrice(new BigDecimal(lineRegularPrice));
        industrialElecPrice.setLineLowValleyPrice(new BigDecimal(lineLowValleyPrice));
        industrialElecPrice.setExecutionTime(executionTime);
        industrialElecPrice.setVoltageLevel(VoltageLevel.getVoltageLevel(array.getJSONObject(0).getString("words")));

        String transmissionPrice = array.getJSONObject(7).getString("words");
        industrialElecPrice.setTransmissionPrice(new BigDecimal(transmissionPrice));
        industrialElecPrice.setRunningPrice(new BigDecimal(runningPrice));
        industrialElecPrice.setAddPrice(new BigDecimal(addPrice));

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

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

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

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

        industrialElecPrice.setCreateTime(new Date());
        industrialElecPrice.setRegionId(regionId);
        industrialElecPrice.setSpikePriceInterval(spikePriceInterval);
        industrialElecPrice.setPeakPriceInterval(peakPriceInterval);
        industrialElecPrice.setRegularPriceInterval(regularPriceInterval);
        industrialElecPrice.setLowValleyPriceInterval(lowValleyPriceInterval);
        industrialElecPrice.setDeepValleyPriceInterval(deepValleyPriceInterval);
        list.add(industrialElecPrice);
        int a=0;
        for (int i = 0; i < rowStart; i++) {
            IndustrialElecPrice industrialElecPrice1 = new IndustrialElecPrice();

            industrialElecPrice1.setFeedPeakPrice(new BigDecimal(feedPeakPrice));
            industrialElecPrice1.setFeedRegularPrice(new BigDecimal(feedRegularPrice));
            industrialElecPrice1.setFeedLowValleyPrice(new BigDecimal(feedLowValleyPrice));
            industrialElecPrice1.setLinePeakPrice(new BigDecimal(linePeakPrice));
            industrialElecPrice1.setLineRegularPrice(new BigDecimal(lineRegularPrice));
            industrialElecPrice1.setLineLowValleyPrice(new BigDecimal(lineLowValleyPrice));
            industrialElecPrice1.setRunningPrice(new BigDecimal(runningPrice));
            industrialElecPrice1.setAddPrice(new BigDecimal(addPrice));
            industrialElecPrice1.setExecutionTime(executionTime);
            industrialElecPrice1.setVoltageLevel(VoltageLevel.getVoltageLevel(array.getJSONObject(15+a).getString("words")));
            industrialElecPrice1.setRegionId(regionId);

            transmissionPrice = array.getJSONObject(16+a).getString("words");

            industrialElecPrice1.setTransmissionPrice(new BigDecimal(transmissionPrice));

            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));
            }

            capacityPrice = array.getJSONObject(21+a).getString("words");
            if (VoltageLevel.isNumeric(capacityPrice)) {
                industrialElecPrice1.setCapacityPrice(new BigDecimal(capacityPrice));
                industrialElecPrice1.setElectricityType(2);
                industrialElecPrice1.setCustomerType(2);
            }else{
                industrialElecPrice1.setElectricityType(1);
                industrialElecPrice1.setCustomerType(1);
            }
            industrialElecPrice1.setCreateTime(new Date());
            industrialElecPrice1.setSpikePriceInterval(spikePriceInterval);
            industrialElecPrice1.setPeakPriceInterval(peakPriceInterval);
            industrialElecPrice1.setRegularPriceInterval(regularPriceInterval);
            industrialElecPrice1.setLowValleyPriceInterval(lowValleyPriceInterval);
            industrialElecPrice1.setDeepValleyPriceInterval(deepValleyPriceInterval);
            a=a+7;
            list.add(industrialElecPrice1);
        }
       return list;
    }
}
