package com.gyee.wisdom.dao.simulator;

import com.gyee.wisdom.common.data.timeseries.*;
import com.gyee.wisdom.common.utils.DateUtil;
import com.gyee.wisdom.dao.timeseries.EDosDao;
import com.gyee.wisdom.dao.timeseries.ILatestDao;
import com.gyee.wisdom.dao.timeseries.SimulatorDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
@Slf4j
@SimulatorDao
public class SimulatorLatestDao implements ILatestDao {


    public Map<String, TsData> getTsDataLatest(List<TsPoint> tsPoints) throws Exception {
        Map<String, TsData> result = new HashMap<String, TsData>();
        try {
            String[] ids = tsPoints.stream().map(TsPoint::getId).toArray(String[]::new);


            long ts = new Date().getTime();
            for (int i = 0; i < ids.length; i++) {
                if (tsPoints.get(i).getTsDataType() == TsDataType.BOOLEAN) {
                    int i1 = (int)(Math.random()*1000)+1;
                    boolean bvalue = (i1 == 5 ? true : false);

                    BooleanTsData tsData = new BooleanTsData(ts, (short) 0, bvalue);
                    result.put(ids[i], tsData);
                } else {
                    double dvalue = new Random().nextDouble();
                    DoubleTsData doubleTsData = new DoubleTsData(ts, (short) 0, dvalue);
                    result.put(ids[i], doubleTsData);
                }
            }

        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return result;
    }


    @Override
    public int writeDoubleLatest(List<TsPointData> list) throws Exception {
        return 0;
    }

    @Override
    public int writeStringLatest(List<TsPointData> list) throws Exception {
        return 0;
    }

    @Override
    public int writeBooleanLatest(List<TsPointData> list) throws Exception {
        return 0;
    }

    @Override
    public int writeLongLatest(List<TsPointData> list) throws Exception {
        return 0;
    }

    @Override
    public int writeBlobLatest(List<TsPointData> list) throws Exception {
        return 0;
    }

    @Override
    public int writeCoordinateLatest(List<TsPointData> list) throws Exception {
        return 0;
    }

    @Override
    public boolean writeLatest(List<TsPointData> dataList) throws Exception {
        return false;
    }

}
