# Copyright 2026 Datastrato, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Request types for the Agentic Data Protocol (ADP).

This module defines the request parameter types for all ADP methods.
"""

from pydantic import BaseModel, ConfigDict, Field

from .common import ClientCapabilities, Implementation, IntentClass, ResourceId
from .intents import Intent
from .jsonrpc import Cursor, RequestParams


class PaginatedRequestParams(RequestParams):
    """Common parameters for paginated requests."""

    cursor: Cursor | None = Field(
        default=None, description="An opaque token representing the current pagination position."
    )


class InitializeRequestParams(RequestParams):
    """Parameters for an `adp.initialize` request."""

    model_config = ConfigDict(extra="allow", populate_by_name=True)

    protocol_version: str = Field(
        alias="protocolVersion", description="The latest version of the ADP protocol that the client supports."
    )
    capabilities: ClientCapabilities = Field(description="Client capabilities.")
    client_info: Implementation = Field(alias="clientInfo", description="Information about the client implementation.")


class DiscoverFilter(BaseModel):
    """Filter criteria for the DISCOVER operation."""

    model_config = ConfigDict(extra="forbid", populate_by_name=True)

    domain_prefix: str | None = Field(
        default=None, alias="domainPrefix", description="Filter resources by domain prefix."
    )
    intent_class: IntentClass | None = Field(
        default=None, alias="intentClass", description="Filter resources by intent class."
    )
    keyword: str | None = Field(default=None, description="Filter resources by keyword search.")


class DiscoverRequestParams(PaginatedRequestParams):
    """Parameters for the `adp.discover` request."""

    filter: DiscoverFilter | None = Field(
        default=None, description="Optional filters to narrow down the resource list."
    )


class DescribeRequestParams(PaginatedRequestParams):
    """Parameters for the `adp.describe` request."""

    resource_id: ResourceId = Field(
        alias="resourceId", description="The unique identifier of the resource to describe."
    )
    intent_class: IntentClass = Field(alias="intentClass", description="The intent class the Agent plans to use.")
    version: int | None = Field(default=None, description="The version of the resource to describe.")


class ValidateRequestParams(RequestParams):
    """Parameters for the `adp.validate` request."""

    intent: Intent = Field(description="The Intent to validate.")


class ExecuteRequestParams(PaginatedRequestParams):
    """Parameters for the `adp.execute` request."""

    intent: Intent = Field(description="The Intent to execute.")
