import { gql } from '@apollo/client'

export const GET_SYSTEM_HEALTH = gql`
  query SystemHealth {
    sites {
      id
      name
      status
    }
    resources {
      id
      name
      status
    }
  }
`

export const GET_COST_OVERVIEW = gql`
  query CostOverview($tenantId: ID!, $timeRange: TimeRangeInput!, $granularity: Granularity!) {
    usage(tenantId: $tenantId, timeRange: $timeRange, granularity: $granularity) {
      tenantId
      totalCost
      currency
      breakdown {
        total
        byResource {
          resourceId
          resourceName
          cost
          percentage
        }
      }
    }
  }
`

export const GET_BILLING_INFO = gql`
  query BillingInfo($tenantId: ID!, $filter: InvoiceFilter!) {
    invoices(tenantId: $tenantId, filter: $filter) {
      id
      invoiceNumber
      billingPeriodStart
      billingPeriodEnd
      subtotal
      tax
      total
      currency
      status
      dueDate
    }
  }
`

export const GET_API_USAGE = gql`
  query DashboardAPIUsage($timeRange: TimeRangeInput!) {
    analyticsAPIUsage(timeRange: $timeRange) {
      totalRequests
      errorRate
      byEndpoint {
        endpoint
        requests
        errors
      }
      byPeriod {
        period
        requests
        errors
      }
    }
  }
`

export const GET_DEPLOYMENTS = gql`
  query DashboardDeployments($filter: DeploymentFilter) {
    deployments(filter: $filter) {
      id
      name
      tenantId
      region
      status
      deploymentType
      createdAt
      updatedAt
    }
  }
`

export const GET_TEST_ENVIRONMENTS = gql`
  query DashboardTestEnvironments {
    testEnvironments {
      id
      name
      userId
      tenantId
      region
      status
      createdAt
      updatedAt
    }
  }
`

export const GET_API_KEYS = gql`
  query DashboardApiKeys {
    apiKeys {
      id
      name
      description
      keyPrefix
      createdAt
      expiresAt
      lastUsedAt
      revoked
    }
  }
`
