import { gql } from '@apollo/client'

export const GET_SYSTEM_HEALTH = gql`
  query GetSystemHealth {
    resources(filter: { status: RUNNING }) {
      id
      name
      type
      status
      site {
        id
        name
        region
      }
    }
    sites {
      id
      name
      status
    }
  }
`

export const GET_RESOURCE_UTILIZATION = gql`
  query GetResourceUtilization($resourceId: ID!, $timeRange: TimeRange!) {
    metrics(resourceId: $resourceId, metricType: CPU_USAGE, timeRange: $timeRange) {
      values {
        timestamp
        value
      }
    }
    resource(id: $resourceId) {
      id
      name
      type
    }
  }
`

export const GET_COST_OVERVIEW = gql`
  query GetCostOverview($tenantId: ID!, $timeRange: TimeRange!) {
    usage(tenantId: $tenantId, timeRange: $timeRange, granularity: DAY) {
      totalCost
      currency
      byResource {
        resourceId
        resourceName
        cost
      }
    }
    costForecast(tenantId: $tenantId, timeframe: "30D", confidence: 0.95) {
      currentCost
      predictedCost
      confidence
      trend
    }
  }
`

export const GET_BILLING_INFO = gql`
  query GetBillingInfo($tenantId: ID!) {
    invoices(tenantId: $tenantId, filter: { status: PENDING }) {
      id
      invoiceNumber
      total
      status
      dueDate
    }
    budgets(tenantId: $tenantId) {
      id
      name
      amount
      currentSpend
      remaining
    }
  }
`

export const GET_API_USAGE = gql`
  query GetAPIUsage($timeRange: TimeRange!) {
    analyticsAPIUsage(timeRange: $timeRange) {
      totalRequests
      byEndpoint {
        endpoint
        requests
        errors
      }
      errorRate
    }
  }
`

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

export const GET_TEST_ENVIRONMENTS = gql`
  query GetTestEnvironments {
    testEnvironments {
      id
      name
      region
      status
      resources {
        vms
        storage
        network
      }
      expiresAt
    }
  }
`

export const GET_API_KEYS = gql`
  query GetAPIKeys {
    apiKeys {
      id
      name
      keyPrefix
      permissions
      lastUsedAt
      expiresAt
      createdAt
    }
  }
`

export const GET_DATA_PIPELINE = gql`
  query GetDataPipeline {
    resources(filter: { type: STORAGE }) {
      id
      name
      status
      metadata
    }
  }
`

export const GET_INTEGRATION_STATUS = gql`
  query GetIntegrationStatus {
    sites {
      id
      name
      status
      region
    }
    omadaSites {
      id
      name
      accessPoints {
        id
        status
      }
    }
  }
`

export const GET_COMPLIANCE_STATUS = gql`
  query GetComplianceStatus($resourceId: ID) {
    policyViolations(filter: { resourceId: $resourceId, status: OPEN }) {
      id
      severity
      message
      policyId
      createdAt
    }
    findings(filter: { status: FAIL }) {
      id
      severity
      title
      description
      resource {
        id
        name
      }
    }
  }
`

export const GET_SERVICE_ADOPTION = gql`
  query GetServiceAdoption {
    resources {
      id
      name
      type
      createdAt
    }
    deployments {
      id
      name
      deploymentType
      createdAt
    }
  }
`

export const GET_RESOURCE_USAGE = gql`
  query GetResourceUsage($tenantId: ID!, $timeRange: TimeRange!) {
    usage(tenantId: $tenantId, timeRange: $timeRange, granularity: HOUR) {
      totalCost
      byResource {
        resourceId
        resourceName
        resourceType
        cost
        quantity
      }
    }
  }
`

