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 Region31 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")));
            industrialElecPrice.setSpikePriceInterval(spikePriceInterval);
            industrialElecPrice.setPeakPriceInterval(peakPriceInterval);
            industrialElecPrice.setRegularPriceInterval(regularPriceInterval);
            industrialElecPrice.setLowValleyPriceInterval(lowValleyPriceInterval);
            industrialElecPrice.setDeepValleyPriceInterval(deepValleyPriceInterval);
            industrialElecPrice.setExecutionTime(executionTime);
            String nonTimePrice = array.getJSONObject(1 + a).getString("words");
            if (VoltageLevel.isNumeric(nonTimePrice)) {
                industrialElecPrice.setNonTimePrice(new BigDecimal(nonTimePrice));
            }

            industrialElecPrice.setRegionId(regionId);
            String proxyPrice = array.getJSONObject(2 + a).getString("words");
            if (VoltageLevel.isNumeric(proxyPrice)) {
                industrialElecPrice.setProxyPrice(new BigDecimal(proxyPrice));
            }

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

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

            String lineLossPrice = array.getJSONObject(5 + a).getString("words");
            if (VoltageLevel.isNumeric(lineLossPrice)) {
                industrialElecPrice.setLineLossPrice(new BigDecimal(lineLossPrice));
            }

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

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

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

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

            String lowValleyPrice = array.getJSONObject(11 + a).getString("words");
            if (VoltageLevel.isNumeric(lowValleyPrice)) {
                industrialElecPrice.setLowValleyPrice(new BigDecimal(lowValleyPrice));
            }

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