import { client } from '@operato/graphql';
import gql from 'graphql-tag';
import { showToast } from '../../../shared/utils/alert';
export const getInverterStatusByPowerPlantId = async (powerPlantId) => {
    const response = await client.query({
        query: gql `
      query InverterStatusListByPowerPlantId($powerPlantId: String!) {
        inverterStatusListByPowerPlantId(powerPlantId: $powerPlantId) {
          ivtId
          id
          ac
          dc
          acc
          ds
          run
          com
          isNoSignal
          collectedAt
        }
      }
    `,
        variables: { powerPlantId }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return {
        status: true,
        data: response.data.inverterStatusListByPowerPlantId
    };
};
export const getInverterSummaryDailyByPowerPlantId = async (powerPlantId, date) => {
    const response = await client.query({
        query: gql `
      query InverterSummaryDailyByPowerPlantId($powerPlantId: String!, $date: String!) {
        inverterSummaryDailyByPowerPlantId(powerPlantId: $powerPlantId, date: $date) {
          date
          value
          generationTime
        }
      }
    `,
        variables: { powerPlantId, date }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return response.data.inverterSummaryDailyByPowerPlantId;
};
export const getInverterSummaryMonthlyByPowerPlantId = async (powerPlantId, date) => {
    const response = await client.query({
        query: gql `
      query InverterSummaryMonthlyByPowerPlantId($powerPlantId: String!, $date: String!) {
        inverterSummaryMonthlyByPowerPlantId(powerPlantId: $powerPlantId, date: $date) {
          no
          date
          value
          generationTime
        }
      }
    `,
        variables: { powerPlantId, date }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return response.data.inverterSummaryMonthlyByPowerPlantId;
};
export const getInverterSummaryYearlyByPowerPlantId = async (powerPlantId, date) => {
    const response = await client.query({
        query: gql `
      query InverterSummaryYearlyByPowerPlantId($powerPlantId: String!, $date: String!) {
        inverterSummaryYearlyByPowerPlantId(powerPlantId: $powerPlantId, date: $date) {
          no
          date
          value
          generationTime
        }
      }
    `,
        variables: { powerPlantId, date }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return response.data.inverterSummaryYearlyByPowerPlantId;
};
export const getInverterSeperateDailyByPowerPlantId = async (powerPlantId, date) => {
    const response = await client.query({
        query: gql `
      query InverterSeperateDailyByPowerPlantId($powerPlantId: String!, $date: String!) {
        inverterSeperateDailyByPowerPlantId(powerPlantId: $powerPlantId, date: $date) {
          no
          date
          value
          generationTime
        }
      }
    `,
        variables: { powerPlantId, date }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return response.data.inverterSeperateDailyByPowerPlantId;
};
export const getInverterSeperateMonthlyByPowerPlantId = async (powerPlantId, date) => {
    const response = await client.query({
        query: gql `
      query InverterSeperateMonthlyByPowerPlantId($powerPlantId: String!, $date: String!) {
        inverterSeperateMonthlyByPowerPlantId(powerPlantId: $powerPlantId, date: $date) {
          no
          date
          value
          generationTime
        }
      }
    `,
        variables: { powerPlantId, date }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return response.data.inverterSeperateMonthlyByPowerPlantId;
};
export const getInverterSeperateYearlyByPowerPlantId = async (powerPlantId, date) => {
    const response = await client.query({
        query: gql `
      query InverterSeperateYearlyByPowerPlantId($powerPlantId: String!, $date: String!) {
        inverterSeperateYearlyByPowerPlantId(powerPlantId: $powerPlantId, date: $date) {
          no
          date
          value
          generationTime
        }
      }
    `,
        variables: { powerPlantId, date }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return response.data.inverterSeperateYearlyByPowerPlantId;
};
export const getInverterDetailByPowerPlantId = async (powerPlantId) => {
    const response = await client.query({
        query: gql `
      query InverterDetailByPowerPlantId($powerPlantId: String!) {
        inverterDetailByPowerPlantId(powerPlantId: $powerPlantId) {
          no
          description
          com
          run
          ac
          dc
          DC_V
          DC_I
          DC_P
          IV_R
          IV_S
          IV_T
          IC_R
          IC_S
          IC_T
          AC_P
          isNoSignal
          collectedAt
        }
      }
    `,
        variables: { powerPlantId }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return {
        status: true,
        data: response.data.inverterDetailByPowerPlantId
    };
};
export const getInverterHistoriesByDate = async (powerPlantId, inverterId, dateType, date, page, limit) => {
    const response = await client.query({
        query: gql `
      query InverterHistoriesByDate(
        $powerPlantId: String!
        $inverterId: String!
        $dateType: String!
        $date: String!
        $page: Float!
        $limit: Float!
      ) {
        inverterHistoriesByDate(
          powerPlantId: $powerPlantId
          inverterId: $inverterId
          dateType: $dateType
          date: $date
          page: $page
          limit: $limit
        ) {
          items {
            no
            PF
            DC_V
            DC_I
            DC_P
            IV_R
            IV_S
            IV_T
            IC_R
            IC_S
            IC_T
            AC_P
            dailyGeneration
            totalGeneration
            collectedAt
            DATE_INFO
          }
          total
        }
      }
    `,
        variables: { powerPlantId, inverterId, dateType, date, page, limit }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return {
        status: true,
        data: response.data.inverterHistoriesByDate
    };
};
export const getAllInverterHistoriesByDate = async (powerPlantId, date) => {
    const response = await client.query({
        query: gql `
      query AllInverterHistoriesByDate($powerPlantId: String!, $date: String!) {
        allInverterHistoriesByDate(powerPlantId: $powerPlantId, date: $date) {
          no
          PF
          DC_V
          DC_I
          DC_P
          IV_R
          IV_S
          IV_T
          IC_R
          IC_S
          IC_T
          AC_P
          dailyGeneration
          totalGeneration
          collectedAt
          DATE_INFO
        }
      }
    `,
        variables: { powerPlantId, date }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return response.data.allInverterHistoriesByDate;
};
export const getInverterRtuBindingListByPowerPlantId = async (powerPlantId) => {
    const response = await client.query({
        query: gql `
      query InverterRtuBindingListByPowerPlantId($powerPlantId: String!) {
        inverterRtuBindingListByPowerPlantId(powerPlantId: $powerPlantId) {
          id
          name
          capacity
        }
      }
    `,
        variables: { powerPlantId }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return { status: false, data: [] };
    }
    return response.data.inverterRtuBindingListByPowerPlantId;
};
export const getInverterSummaryBetweenDate = async (powerPlantId, startDate, endDate) => {
    const response = await client.query({
        query: gql `
      query InverterSummaryBetweenDate($powerPlantId: String!, $startDate: String!, $endDate: String!) {
        inverterSummaryBetweenDate(powerPlantId: $powerPlantId, startDate: $startDate, endDate: $endDate) {
          dailyAverageGenerationTime
        }
      }
    `,
        variables: { powerPlantId, startDate, endDate }
    });
    if (response.errors) {
        showToast('요청에 실패하였습니다');
        return [];
    }
    return response.data.inverterSummaryBetweenDate;
};
//# sourceMappingURL=query.js.map