import { client } from '@operato/graphql';
import gql from 'graphql-tag';
import { showToast } from '../../../shared/utils/alert';
export const getTodaySmpAndRec = async () => {
    const response = await client.query({
        query: gql `
      query TodaySmpAndRec {
        todaySmp {
          TRAD_DAY
          AVG_PRC
          LOW_PRC
          HIGH_PRC
        }
        todayRec {
          TRAD_DAY
          AVG_PRC
          LOW_PRC
          HIGH_PRC
        }
      }
    `
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: {} };
    }
    return {
        status: true,
        data: response.data
    };
};
export const getThisMonthSmpAndRec = async () => {
    const response = await client.query({
        query: gql `
      query ThisMonthSmpAndRec {
        thisMonthSmpAndRec {
          SMP {
            AVG_PRC
          }
          REC {
            AVG_PRC
          }
        }
      }
    `
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: {} };
    }
    return {
        status: true,
        data: response.data.thisMonthSmpAndRec
    };
};
export const getSmps = async (fromDate, toDate, page, limit) => {
    const response = await client.query({
        query: gql `
      query Smps($fromDate: String!, $toDate: String!, $page: Float!, $limit: Float!) {
        smps(fromDate: $fromDate, toDate: $toDate, page: $page, limit: $limit) {
          items {
            date
            HIGH_PRC
            LOW_PRC
            AVG_PRC
          }
          total
        }
      }
    `,
        variables: { fromDate, toDate, page, limit }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: { items: [], total: 0 } };
    }
    return {
        status: true,
        data: response.data.smps
    };
};
export const getRecs = async (fromDate, toDate, page, limit) => {
    const response = await client.query({
        query: gql `
      query Recs($fromDate: String!, $toDate: String!, $page: Float!, $limit: Float!) {
        recs(fromDate: $fromDate, toDate: $toDate, page: $page, limit: $limit) {
          items {
            date
            HIGH_PRC
            LOW_PRC
            AVG_PRC
          }
          total
        }
      }
    `,
        variables: { fromDate, toDate, page, limit }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: { items: [], total: 0 } };
    }
    return {
        status: true,
        data: response.data.recs
    };
};
//# sourceMappingURL=query.js.map