from typing import Any, Dict, List, Optional, Union
from metorial._endpoint import BaseMetorialEndpoint, MetorialEndpointManager, MetorialRequest
from ..resources import mapDashboardInstanceFilesListOutput, DashboardInstanceFilesListOutput, mapDashboardInstanceFilesListQuery, DashboardInstanceFilesListQuery, mapDashboardInstanceFilesGetOutput, DashboardInstanceFilesGetOutput, mapDashboardInstanceFilesDeleteOutput, DashboardInstanceFilesDeleteOutput

class MetorialDashboardInstanceFilesEndpoint(BaseMetorialEndpoint):
    """Represents files that you have uploaded to Metorial. Files can be linked to various resources based on their purpose. Metorial can also automatically extract files for you, for example for data exports."""

    def __init__(self, config: MetorialEndpointManager):
        super().__init__(config)

    def list(self, instance_id: str, *, limit: Optional[float] = None, after: Optional[str] = None, before: Optional[str] = None, cursor: Optional[str] = None, order: Optional[str] = None, purpose: Optional[str] = None) -> DashboardInstanceFilesListOutput:
        """
    List instance files
    Returns a paginated list of files owned by the instance.

    :param instance_id: str
    :param limit: Optional[float] (optional)
    :param after: Optional[str] (optional)
    :param before: Optional[str] (optional)
    :param cursor: Optional[str] (optional)
    :param order: Optional[str] (optional)
    :param purpose: Optional[str] (optional)
    :return: DashboardInstanceFilesListOutput
    """
        # Build query parameters from keyword arguments
        query_dict = {}
        if limit is not None:
            query_dict["limit"] = limit
        if after is not None:
            query_dict["after"] = after
        if before is not None:
            query_dict["before"] = before
        if cursor is not None:
            query_dict["cursor"] = cursor
        if order is not None:
            query_dict["order"] = order
        if purpose is not None:
            query_dict["purpose"] = purpose

        request = MetorialRequest(
            path=['dashboard', 'instances', instance_id, 'files'],
            query=query_dict
        )
        return self._get(request).transform(mapDashboardInstanceFilesListOutput.from_dict)

    def get(self, instance_id: str, file_id: str) -> DashboardInstanceFilesGetOutput:
        """
    Get file by ID
    Retrieves details for a specific file by its ID.

    :param instance_id: str
    :param file_id: str
    :return: DashboardInstanceFilesGetOutput
    """
        request = MetorialRequest(
            path=['dashboard', 'instances', instance_id, 'files', file_id]
        )
        return self._get(request).transform(mapDashboardInstanceFilesGetOutput.from_dict)

    def delete(self, instance_id: str, file_id: str) -> DashboardInstanceFilesDeleteOutput:
        """
    Delete file by ID
    Deletes a specific file by its ID.

    :param instance_id: str
    :param file_id: str
    :return: DashboardInstanceFilesDeleteOutput
    """
        request = MetorialRequest(
            path=['dashboard', 'instances', instance_id, 'files', file_id]
        )
        return self._delete(request).transform(mapDashboardInstanceFilesDeleteOutput.from_dict)