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 Region24 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");

        int a = 0;
        for (int i = 0; i < rowStart+1; i++) {
            IndustrialElecPrice industrialElecPrice1 = new IndustrialElecPrice();
            industrialElecPrice1.setVoltageLevel(VoltageLevel.getVoltageLevel(array.getJSONObject(0+a).getString("words")));
            if(i<4){
                industrialElecPrice1.setCustomerType(2);
            }else{
                industrialElecPrice1.setCustomerType(1);
            }
            industrialElecPrice1.setSpikePriceInterval(spikePriceInterval);
            industrialElecPrice1.setPeakPriceInterval(peakPriceInterval);
            industrialElecPrice1.setRegularPriceInterval(regularPriceInterval);
            industrialElecPrice1.setLowValleyPriceInterval(lowValleyPriceInterval);
            industrialElecPrice1.setDeepValleyPriceInterval(deepValleyPriceInterval);
            industrialElecPrice1.setExecutionTime(executionTime);

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

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

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

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

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

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

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

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

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

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

            String capacityPrice = array.getJSONObject(13+ a).getString("words");
            if (VoltageLevel.isNumeric(capacityPrice)) {
                industrialElecPrice1.setCapacityPrice(new BigDecimal(capacityPrice));
            }
            industrialElecPrice1.setRegionId(regionId);
            industrialElecPrice1.setCreateTime(new Date());
            a = a + 14;
            list.add(industrialElecPrice1);
        }
        return list;
    }
}
