import { createSlice } from "@reduxjs/toolkit";


interface MetricsState {
    metrics: [
        {
            index: number;                      //序号
            id: string;                         //id
            name: string;                       //名称
            description: string | '';           //描述
            require_permission: boolean | false;//是否需要授权
            record_format: [
                {
                    name: string;
                    default_value: number;
                    //取值类型（整数、小数）
                    //取值精度（小数点后几位）
                    step: number;           //步长
                    min: number;            //最小值
                    max: number;            //最大值  
                    default_unit: string;           //单位
                }
            ] | []
            all_records: [
                {
                    record: [
                        {
                            name: string;
                            value: number;
                            unit: string;
                        }
                    ],
                    timestamp: number;
                    // note: string | ''
                }

            ] | [];
        },
    ];
}

const initialState: MetricsState = {
    metrics:[
        {
            index: 0,
            id: '',
            name: '',
            description: '',
            require_permission: false,
            record_format: [
                {
                    name: '',
                    default_value: 0,
                    step: 0,
                    min: 0,
                    max: 0,
                    default_unit: '',
                }
            ],
            all_records: [
                {
                    record: [
                        {
                            name: '',
                            value: 0,
                            unit: '',
                        }
                    ],
                    timestamp: 0,
                }
            ]
        }
    ]
};


const metricsSlice = createSlice({
    name: 'metrics',
    initialState,
    reducers: {
        getMetricsSuccess(state, action) { }

    }
})




export const { getMetricsSuccess } = metricsSlice.actions;
export default metricsSlice.reducer;