import { gql } from '@apollo/client'

export const GET_COUNTRIES = gql`
  query GetCountries($filter: CountryFilter) {
    countries(filter: $filter) {
      name
      region
      relationshipType
      priority
      cloudflareCoverage
      networkInfrastructurePriority
      notes
      coordinates {
        lat
        lng
      }
    }
  }
`

export const GET_COUNTRY = gql`
  query GetCountry($name: String!) {
    country(name: $name) {
      name
      region
      relationshipType
      priority
      cloudflareCoverage
      networkInfrastructurePriority
      notes
      coordinates {
        lat
        lng
      }
    }
  }
`

export const GET_NETWORK_TOPOLOGIES = gql`
  query GetNetworkTopologies($filter: TopologyFilter) {
    networkTopologies(filter: $filter) {
      id
      nodes {
        id
        type
        label
        region
        entity
        position {
          x
          y
        }
        metadata
      }
      edges {
        id
        source
        target
        type
        metadata
      }
      region
      entity
      lastUpdated
    }
  }
`

export const GET_NETWORK_TOPOLOGY = gql`
  query GetNetworkTopology($id: ID!) {
    networkTopology(id: $id) {
      id
      nodes {
        id
        type
        label
        region
        entity
        position {
          x
          y
        }
        metadata
      }
      edges {
        id
        source
        target
        type
        metadata
      }
      region
      entity
      lastUpdated
    }
  }
`

export const GET_COMPLIANCE_REQUIREMENTS = gql`
  query GetComplianceRequirements($filter: ComplianceFilter) {
    complianceRequirements(filter: $filter) {
      country
      region
      frameworks
      status
      requirements
      lastAuditDate
      notes
    }
  }
`

export const GET_COMPLIANCE_REQUIREMENT = gql`
  query GetComplianceRequirement($country: String!) {
    complianceRequirement(country: $country) {
      country
      region
      frameworks
      status
      requirements
      lastAuditDate
      notes
    }
  }
`

export const GET_DEPLOYMENT_MILESTONES = gql`
  query GetDeploymentMilestones($filter: MilestoneFilter) {
    deploymentMilestones(filter: $filter) {
      id
      title
      region
      entity
      priority
      startDate
      endDate
      status
      dependencies
      cost
      description
    }
  }
`

export const GET_DEPLOYMENT_MILESTONE = gql`
  query GetDeploymentMilestone($id: ID!) {
    deploymentMilestone(id: $id) {
      id
      title
      region
      entity
      priority
      startDate
      endDate
      status
      dependencies
      cost
      description
    }
  }
`

export const GET_COST_ESTIMATES = gql`
  query GetCostEstimates($filter: CostEstimateFilter) {
    costEstimates(filter: $filter) {
      region
      entity
      category
      monthly
      annual
      breakdown {
        compute
        storage
        network
        licenses
        personnel
      }
      currency
      lastUpdated
    }
  }
`

export const GET_COST_ESTIMATE = gql`
  query GetCostEstimate($region: String!, $entity: String!, $category: CostCategory!) {
    costEstimate(region: $region, entity: $entity, category: $category) {
      region
      entity
      category
      monthly
      annual
      breakdown {
        compute
        storage
        network
        licenses
        personnel
      }
      currency
      lastUpdated
    }
  }
`

export const GET_INFRASTRUCTURE_SUMMARY = gql`
  query GetInfrastructureSummary {
    infrastructureSummary {
      totalCountries
      totalRegions
      totalCost
      deploymentProgress {
        planned
        inProgress
        complete
        blocked
      }
    }
  }
`

export const UPDATE_NETWORK_TOPOLOGY = gql`
  mutation UpdateNetworkTopology($id: ID!, $input: UpdateTopologyInput!) {
    updateNetworkTopology(id: $id, input: $input) {
      id
      nodes {
        id
        type
        label
        region
        entity
        position {
          x
          y
        }
        metadata
      }
      edges {
        id
        source
        target
        type
        metadata
      }
      region
      entity
      lastUpdated
    }
  }
`

export const CREATE_DEPLOYMENT_MILESTONE = gql`
  mutation CreateDeploymentMilestone($input: CreateMilestoneInput!) {
    createDeploymentMilestone(input: $input) {
      id
      title
      region
      entity
      priority
      startDate
      endDate
      status
      dependencies
      cost
      description
    }
  }
`

export const UPDATE_DEPLOYMENT_MILESTONE = gql`
  mutation UpdateDeploymentMilestone($id: ID!, $input: UpdateMilestoneInput!) {
    updateDeploymentMilestone(id: $id, input: $input) {
      id
      title
      region
      entity
      priority
      startDate
      endDate
      status
      dependencies
      cost
      description
    }
  }
`

export const DELETE_DEPLOYMENT_MILESTONE = gql`
  mutation DeleteDeploymentMilestone($id: ID!) {
    deleteDeploymentMilestone(id: $id)
  }
`

export const UPDATE_COMPLIANCE_REQUIREMENT = gql`
  mutation UpdateComplianceRequirement($country: String!, $input: UpdateComplianceInput!) {
    updateComplianceRequirement(country: $country, input: $input) {
      country
      region
      frameworks
      status
      requirements
      lastAuditDate
      notes
    }
  }
`

export const UPDATE_COST_ESTIMATE = gql`
  mutation UpdateCostEstimate(
    $region: String!
    $entity: String!
    $category: CostCategory!
    $input: UpdateCostEstimateInput!
  ) {
    updateCostEstimate(region: $region, entity: $entity, category: $category, input: $input) {
      region
      entity
      category
      monthly
      annual
      breakdown {
        compute
        storage
        network
        licenses
        personnel
      }
      currency
      lastUpdated
    }
  }
`

