#
# Copyright (c) 2025 Broadcom Inc. and its subsidiaries. All Rights Reserved.
#

extend type Query {
    "Get all policies"
    policies : [L7Policy!]!

    "Get policies inside a folder"
    policiesByFolderPath(folderPath: String!) : [L7Policy!]!

    "Get specified type policies"
    policiesByType(policyType: L7PolicyType!, tag: String, subTag: String) : [L7Policy!]!

    "Get specified type policies inside a folder"
     policiesByFolderPathAndType(folderPath: String!, policyType: L7PolicyType!, tag: String, subTag: String) : [L7Policy!]!

    "Get policy by goid"
    policyByGoid(goid: ID!) : L7Policy

    "Get policy by name"
    policyByName(name: String!) : L7Policy

    "Get policy by guid"
    policyByGuid(guid: ID!) : L7Policy

    "(Deprecated) Get policy and it's revision by name and revision ordinal"
    policyByNameAndRevision(name: String!, revision: Long!) : L7Policy @deprecated(reason: "Use 'policyByName' instead along with the selector over 'policyRevisions'.")

    "Get filtered policies"
    policiesByFilters(filters: [EntityFilterInput!]!) : [L7Policy!]!
}

extend type Mutation {
    "Create or update policies"
    setPolicies(input: [L7PolicyInput!]!) : L7PoliciesPayload!

    """"
    Set active revision for the policies.
    By default, it chooses the latest revision as active. If the latest revision available is already active, does nothing.
    """
    setPolicyRevisions(input: [L7PolicyPartialInput!]!) : L7PoliciesPayload!

    """"
    Delete policies.
    
    This mutation supports two ways to identify policies for deletion:
    1. **refInputs** (recommended): A list of PolicyRefInput objects that uniquely identify policies by name, policyType, and optional tag/subTag
    2. **names** (deprecated): A list of policy names as strings
    
    When both arguments are provided, refInputs takes precedence and names is ignored.
    At least one argument must be provided with a non-empty list.
    """
    deletePolicies(refInputs: [PolicyRefInput!], names: [String!] @deprecated(reason: "Use 'refInputs' instead for more precise policy identification")) : L7PoliciesPayload!

    "Update an existing policy. Match is carried by refInput"
    updatePolicy(refInput: PolicyRefInput!,  input: L7PolicyPartialInput!) : L7PolicyPayload!

    "Update existing revision (comment and/or active) for the specified policy"
    updatePolicyRevision(refInput: PolicyRefInput!, revision: Long!, activate: Boolean, comment: String) : L7PolicyPayload!

    "(Deprecated) Update existing revision (comment and/or active) for the policies"
    updatePoliciesRevision(input: [L7PolicyPartialInput!]!, activate: Boolean!, comment: String) : L7PoliciesPayload!
}

 """
 A Layer7 gateway policy
> @l7-entity policy|policies
> @l7-identity-fields name,policyType
> @l7-summary-fields goid,guid,name,policyType,tag,subTag,checksum
> @l7-excluded-fields policy.directDependencies,policy.allDependencies,policyRevision,policyRevisions
> @l7-name-fields name
> @l7-display-summary-fields name,policyType,enabled
> @l7-alternative-fields policy.xml|policy.json|policy.yaml|policy.code,policyRevision.xml|policyRevision.json|policyRevision.yaml|policyRevision.code,policyRevisions.xml|policyRevisions.json|policyRevisions.yaml|policyRevisions.code
 """
 type L7Policy {
    "The goid for this policy"
    goid : ID!
    "The guid for this policy"
    guid : ID!
    "The name of the policy (policies are unique by name)"
    name: String!
    "The type of policy"
    policyType: L7PolicyType!
    "The policy tag"
    tag: String
    "The policy sub-tag"
    subTag: String
    "The configuration checksum"
    checksum: String!

    "The policy version"
    version: Int

    "Is the policy enabled or not"
    enabled: Boolean!

    "The folder path to the policy"
    folderPath: String!
    "Is soap"
    soap: Boolean

    "The actual policy and dependencies"
    policy: Policy!
    "(Deprecated) The policy revision. It can be either the active revision or the specific one when queried explicitly."
    policyRevision: PolicyRevision
    """
    The policy revisions.
    When [selected] argument is not empty, selected revisions will be returned.
    If not, all the revisions will be returned.
    NOTE: Use 0 to select active revision. Use -1 to select latest revision.
    """
    policyRevisions(selected: [Long!]): [PolicyRevision!]!
 }

  type L7PolicyPayload implements EntityMutationPayload {
    status: EntityMutationStatus!
    detailedStatus: EntityMutationDetailedStatus!
    policy: L7Policy
  }

  type L7PoliciesPayload implements EntityMutationsPayload {
    status: [EntityMutationStatus!]!
    detailedStatus: [EntityMutationDetailedStatus!]!
    policies: [L7Policy]!
  }

 enum L7PolicyType {
    FRAGMENT
    PRE_ROUTING_FRAGMENT
    SUCCESSFUL_ROUTING_FRAGMENT
    FAILED_ROUTING_FRAGMENT
    AUTHENTICATION_SUCCESS_FRAGMENT
    AUTHENTICATION_FAILURE_FRAGMENT
    AUTHORIZATION_SUCCESS_FRAGMENT
    AUTHORIZATION_FAILURE_FRAGMENT
    GLOBAL
    INTERNAL
    POLICY_BACKED_IDP
    POLICY_BACKED_OPERATION
    POLICY_BACKED_BACKGROUND_TASK
    POLICY_BACKED_SERVICE_METRICS
 }

 """
 Wrapper for the policy XML and the dependencies they include
 > @l7-excluded-fields json,yaml,code,directDependencies,allDependencies
 > @l7-alternative-fields xml|json|yaml|code,json|xml|yaml|code,yaml|xml|json|code,code|xml|json|yaml
 """
 type Policy {
    "The policy XML"
    xml: String
    "The policy JSON"
    json: String
    "The policy YAML"
    yaml: String
    "The policy code"
    code: JSON
    "Entities that are directly referred to inside the policy XML"
    directDependencies: PolicyDependency
    "Entities that are directly referred to inside the policy XML in addition to ones in policy dependencies. More than second level, this keep going as deep as needed until no dependencies are found"
    allDependencies: PolicyDependency
 }

 """
 Wrapper for the policy revision
 > @l7-excluded-fields json,yaml,code
 > @l7-alternative-fields xml|json|yaml|code,json|xml|yaml|code,yaml|xml|json|code,code|xml|json|yaml
 """
 type PolicyRevision {
    goid: ID!
    ordinal: Long!
    active: Boolean!
    comment: String
    author: String
    time: DateTime!
    "The policy XML"
    xml: String
    "The policy JSON"
    json: String
    "The policy YAML"
    yaml: String
    "The policy code"
    code: JSON
 }

 """
 Policy Dependency contains all dependencies that may be referred to from the policy XML this is associated with
 > @l7-excluded-fields fips,fipUsers,fipGroups,ldaps,policyFragments
 """
 type PolicyDependency {
    "Active Connectors (SFTP, MQ Native, Kafka)"
    activeConnectors: [ActiveConnector]
    "Cassandra connections"
    cassandraConnections: [CassandraConnection]
    "Cluster properties"
    clusterProperties : [ClusterProperty]
    "Custom key values"
    customKeyValues: [CustomKeyValue]
    "DTDs in global resources"
    dtds: [Dtd]
    "Email Listeners"
    emailListeners: [EmailListener]
    "Encass Configs"
    encassConfigs : [EncassConfig]

    "Federated identity provider configurations"
    fips : [Fip]
    "Federated identity provider groups"
    fipGroups : [FipGroup]
    "Federated identity provider users"
    fipUsers : [FipUser]
    "Federated identity provider configurations"
    federatedIdps : [FederatedIdp]
    "Federated identity provider groups"
    federatedGroups : [FederatedGroup]
    "Federated identity provider users"
    federatedUsers : [FederatedUser]
    "Internal IDP providers"
    internalIdps: [InternalIdp]
    "Internal idp groups"
    internalGroups : [InternalGroup]
    "Internal idp users"
    internalUsers : [InternalUser]

    "JDBC connections"
    jdbcConnections: [JdbcConnection]
    "JMS destinations"
    jmsDestinations: [JmsDestination]
    "Private Keys"
    keys : [Key]
    "Ldap identity provider configurations"
    ldaps : [Ldap]
    "Ldap identity provider configurations"
    ldapIdps : [LdapIdp]
    "Listen Ports"
    listenPorts: [ListenPort]
    "Layer7 Services"
    services: [L7Service]
    "Layer7 Policies"
    policies: [L7Policy]
    "Policy Fragments"
    policyFragments : [PolicyFragment]
    "Revocation Check Polices"
    revocationCheckPolicies: [RevocationCheckPolicy]
    "Schemas in global resources"
    schemas: [Schema]
    secrets : [Secret]
    "Server module files (signed modular or custom assertions)"
    serverModuleFiles: [ServerModuleFile]
    "Siteminder Configurations"
    smConfigs: [SMConfig]
    "Trusted certificates"
    trustedCerts : [Certificate]
    "Simple Ldaps"
    simpleLdapIdps : [SimpleLdapIdp]
    "Policy Backed Idps"
    policyBackedIdps : [PolicyBackedIdp]
    "Generic Entities"
    genericEntities : [GenericEntity]
    "Policy Backed Services"
    policyBackedServices: [PolicyBackedService]
 }

 input PolicyInput {
   "The policy xml"
   xml: String
   "The policy JSON"
   json: String
   "The policy YAML"
   yaml: String
   "The policy code"
   code: JSON
 }

 input L7PolicyInput {
   "The internal entity unique identifier"
   goid: ID
   "The folder path where to create this policy.  If the path does not exist, it will be created"
   folderPath: String!
   "The name of the policy. Policies are unique by name."
   name: String!
   "The guid for this policy, if none provided, assigned at creation"
   guid : ID
   "The policy"
   policy: PolicyInput!
   "(Deprecated) The policy revision."
   policyRevision: PolicyRevisionInput
   "The policy revisions."
   policyRevisions: [PolicyRevisionInput!]

   soap: Boolean = false
   policyType: L7PolicyType!
   tag: String
   subTag: String

   "The policy version"
   version: Int

   "Is the policy enabled or not"
   enabled: Boolean = true

   "Ignored at creation time but can be used to compare bundle with gw state"
   checksum : String
 }

  input L7PolicyPartialInput {
    "The internal entity unique identifier"
    goid: ID
    "The folder path where to create this policy.  If the path does not exist, it will be created"
    folderPath: String
    "The name of the policy. Policies are unique by name."
    name: String
    "The guid for this policy, if none provided, assigned at creation"
    guid : ID
    "The policy"
    policy: PolicyInput
    "(Deprecated) The policy revision."
    policyRevision: PolicyRevisionInput
    "The policy revisions."
    policyRevisions: [PolicyRevisionInput!]

    "The policy version"
    version: Int
    "Is the policy enabled or not"
    enabled: Boolean
    soap: Boolean = false
    policyType: L7PolicyType
    tag: String
    subTag: String

    "Ignored at creation time but can be used to compare bundle with gw state"
    checksum : String
  }

 input PolicyRevisionInput {
    goid: ID
    ordinal: Long!
    active: Boolean
    comment: String
    author: String
    time: DateTime
    "The policy XML"
    xml: String
    "The policy JSON"
    json: String
    "The policy YAML"
    yaml: String
    "The policy code"
    code: JSON
 }

input PolicyMappingInstructionInput{
    action: EntityMutationAction!
    default: Boolean
    failOnNew: Boolean
    failOnExisting: Boolean
    nodef: Boolean
    "one or more name-value pairs to identify a Policy entity uniquely"
    source: PolicyRefInput
}

input PolicyRefInput {
    "The name of the policy. Policies are unique by name."
    name: String!
    policyType: L7PolicyType!
    tag: String
    subTag: String
}
