import APP from '@/services';
import moment from 'moment';
import { commonSearch_go } from '../index';
// import * as type from './interface';

/**
 * 获取服务器时间
 */
export function getServerTime(): Promise<string> {
    return commonSearch_go('/Market/QueryMarketRun', {})
        .then((res) => {
            const time = moment(res)
                .utc()
                .format('YYYY-MM-DD HH:mm:ss');
            APP.set('systemDate', time);
            return 'ok';
        })
        .catch((err: Error) => {
            throw new Error('获取服务器时间数据错误：' + err);
        });
}

/**
 * 查询市场运行信息
 * /Market/QueryMarketRun
 * marketID 市场ID，不传返回所有
 */
export function queryMarketRun(marketID?: number): Promise<string> {
    const param = marketID ? { marketID } : {}
    return commonSearch_go('/Market/QueryMarketRun', param).then(res => {
        console.log('市场运行信息', res)
        APP.set('marketRun', res);
        return 'ok';
    }).catch((err) => {
        throw new Error(`查询市场运行信息: ${err}`);
    });
}