import { client } from '@operato/graphql';
import gql from 'graphql-tag';
import { showToast } from '../../shared/utils/alert';
export const QUERY_POWER_USAGE_BY_DATE = `
  powerUsageByDate(powerPlantId: $powerPlantId, date: $date) {
    date
    hour
    usage
    maxDemand
    fee
    hourlyApplyPricing
    criteriaTime: hour
    createdAt
  }
`;
export const QUERY_POWER_USAGE_SUMMARY_BY_YEAR_MONTH = `
  powerUsageSummaryByYearMonth(powerPlantId: $powerPlantId, yearMonth: $yearMonth) {
    date
    usage
    maxDemand
    fee
    hourlyApplyPricing
    criteriaTime: date
  }
`;
export const QUERY_POWER_USAGE_SUMMARY_BY_YEAR = `
  powerUsageSummaryByYear(powerPlantId: $powerPlantId, year: $year) {
    date
    usage
    maxDemand
    fee
    hourlyApplyPricing
    criteriaTime: date
  }
`;
export const getPowerUsageByDate = async (powerPlantId, date) => {
    const response = await client.query({
        query: gql `
      query PowerUsageByDate($powerPlantId: String!, $date: String!) {
       ${QUERY_POWER_USAGE_BY_DATE}
      }
    `,
        variables: { powerPlantId, date }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return [];
    }
    return response.data.powerUsageByDate;
};
export const getPowerUsageSummaryByYearMonth = async (powerPlantId, yearMonth) => {
    const response = await client.query({
        query: gql `
      query PowerUsageSummaryByYearMonth($powerPlantId: String!, $yearMonth: String!) {
       ${QUERY_POWER_USAGE_SUMMARY_BY_YEAR_MONTH}
      }
    `,
        variables: { powerPlantId, yearMonth }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return [];
    }
    return response.data.powerUsageSummaryByYearMonth;
};
export const getPowerUsageSummaryByYear = async (powerPlantId, year) => {
    const response = await client.query({
        query: gql `
      query PowerUsageSummaryByYear($powerPlantId: String!, $year: String!) {
       ${QUERY_POWER_USAGE_SUMMARY_BY_YEAR}
      }
    `,
        variables: { powerPlantId, year }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return [];
    }
    return response.data.powerUsageSummaryByYear;
};
export const getPowerUsageSummaryByDate = async (powerPlantId, startDate, endDate) => {
    const response = await client.query({
        query: gql `
      query PowerUsageSummaryByDate($powerPlantId: String!, $startDate: String!, $endDate: String!) {
        powerUsageSummaryByDate(powerPlantId: $powerPlantId, startDate: $startDate, endDate: $endDate) {
          date
          usage
          hourlyApplyPricing
        }
      }
    `,
        variables: {
            powerPlantId,
            startDate,
            endDate
        }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: {} };
    }
    return {
        status: true,
        data: response.data.powerUsageSummaryByDate
    };
};
//# sourceMappingURL=query.js.map