
import { API_ACTIVITY_CARDS, API_ACTIVITY_RECORDS, API_METRIC_CARDS, API_METRIC_FOLLOWS, API_METRIC_GROUPS, API_METRIC_RECORDS, API_UPLOAD_STEPS } from './http/api';
import { request } from './http/request';

export const uploadSteps = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_UPLOAD_STEPS, method: 'POST', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(err => {
            reject(err)
        })
    })
}

export const activityCards = () => {
    return new Promise((resolve, reject) => {
        request({
            url: API_ACTIVITY_CARDS, method: 'GET', data: {}
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

export const activityRecords = (params) => {
    return new Promise((resolve) => {
        request({
            url: API_ACTIVITY_RECORDS, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        })
    })
}

export const cleartActivityRecords = (params) => {
    return new Promise((resolve) => {
        request({
            url: API_ACTIVITY_RECORDS + '?code=' + params.code, method: 'DELETE', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        })
    })

}

export const metricGroups = ()=>{
    return new Promise((resolve) => {
        request({
            url: API_METRIC_GROUPS, method: 'GET', data: {}
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        })
    })
}

export const clearMetricRecords = (params) => {
    return new Promise((resolve) => {
        request({
            url: API_METRIC_RECORDS + '?code=' + params.code, method: 'DELETE', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        })
    })


}

export const deleteMetricRecord = (params) => {
    return new Promise((resolve) => {
        request({
            url: API_METRIC_RECORDS + '/' + params.id, method: 'DELETE', data: {}
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        })
    })


}

export const deleteActivityRecord = (params) => {
    return new Promise((resolve) => {
        request({
            url: API_ACTIVITY_RECORDS + '/' + params.id, method: 'DELETE', data: {}
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        })
    })


}

export const uploadMetric = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_METRIC_RECORDS, method: 'POST', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(err => {
            reject(err)
            global.postBtnUpdateStatus('idle')

        })
    })
}

export const metricCards = () => {
    return new Promise((resolve, reject) => {
        request({
            url: API_METRIC_CARDS, method: 'GET', data: {}
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

export const metricRecords = (params) => {
    return new Promise((resolve) => {
        request({
            url: API_METRIC_RECORDS, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        })
    })
}

export const metricFollows = (params) => {
    return new Promise((resolve) => {
        request({
            url: API_METRIC_FOLLOWS, method: 'POST', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        })
    })
}

