"""Post-processing response schemas."""

from uuid import UUID
from .common import BaseResponse, Field
from ..enums import FindingType

class MapFindingsRequest(BaseResponse):
    keys: list[str] = Field(
        description=(
            "List of finding key fields to use for mapping. If not provided, all "
            "available key fields will be used."
        ),
        min_length=1,
    )
    finding_type: FindingType | None = Field(
        default=None,
        description=(
            "Optional finding type filter to apply during mapping. When specified, "
            "only findings with a matching 'finding_classification.finding_type' "
            "will be processed."
        ),
    )
    filter_item_type_id: UUID | None = Field(
        default=None,
        description=(
            "Optional item type ID filter to apply during mapping. When specified, "
            "only findings with a matching 'item_type_version.item_type_id' will be " 
            "processed."
        ),
    )


class BucketFindingsResponse(BaseResponse):
    """Response schema for bucket-scoped findings operations."""

    bucket_id: UUID = Field(..., description="ID of the bucket")
    findings_processed: int = Field(..., description="Number of findings processed")


class BucketCommandsResponse(BaseResponse):
    """Response schema for bucket-scoped commands operations."""

    bucket_id: UUID = Field(..., description="ID of the bucket")
    commands_processed: int = Field(..., description="Number of commands processed")


class AlignmentFindingsResponse(BaseResponse):
    """Response schema for alignment-scoped findings operations."""

    alignment_id: UUID = Field(..., description="ID of the alignment")
    findings_processed: int = Field(..., description="Number of findings processed")


class AlignmentCommandsResponse(BaseResponse):
    """Response schema for alignment-scoped commands operations."""

    alignment_id: UUID = Field(..., description="ID of the alignment")
    commands_processed: int = Field(..., description="Number of commands processed")


class BucketCommandsDropResponse(BaseResponse):
    """Response schema for bucket-scoped command cleanup operations."""

    bucket_id: UUID = Field(..., description="ID of the bucket")
    command_groups_deleted: int = Field(
        ..., description="Number of command groups deleted"
    )
    commands_deleted: int = Field(..., description="Number of commands deleted")
    command_dryruns_deleted: int = Field(
        ..., description="Number of command dry-run records deleted"
    )


class AlignmentCommandsDropResponse(BaseResponse):
    """Response schema for alignment-scoped command cleanup operations."""

    alignment_id: UUID = Field(..., description="ID of the alignment")
    buckets_processed: int = Field(..., description="Number of buckets evaluated")
    command_groups_deleted: int = Field(
        ..., description="Total number of command groups deleted"
    )
    commands_deleted: int = Field(..., description="Total number of commands deleted")
    command_dryruns_deleted: int = Field(
        ..., description="Total number of command dry-run records deleted"
    )


class AlignmentFindingsSummaryReportRequest(BaseResponse):
    """Request schema for findings summary report generation."""

    output_path: str | None = Field(
        default=None,
        description=(
            "Destination path for the generated Excel file. When omitted, the API "
            "stores the report under reports/alignment_<id>_findings_summary.xlsx."
        ),
    )
    sheet_name: str = Field(
        default="findings_summary",
        min_length=1,
        description="Sheet name used inside the generated workbook.",
    )


class AlignmentFindingsSummaryReportResponse(BaseResponse):
    """Response schema for findings summary report generation."""

    alignment_id: UUID = Field(..., description="ID of the alignment")
    output_path: str = Field(..., description="Path of the generated report file")
    sheet_name: str = Field(..., description="Workbook sheet name used for export")
    rows_exported: int = Field(..., description="Number of rows written to the report")
