"""
DCT (Discrete Cosine Transform) image embedding backend.

Wraps the existing frequency-domain DCT functions in dct_steganography.py.
"""

from __future__ import annotations

from typing import Any


class DCTBackend:
    """Frequency-domain DCT embedding for JPEG-resilient steganography."""

    @property
    def mode(self) -> str:
        return "dct"

    @property
    def carrier_type(self) -> str:
        return "image"

    def is_available(self) -> bool:
        from ..dct_steganography import HAS_SCIPY

        return HAS_SCIPY

    def embed(
        self,
        data: bytes,
        carrier: bytes,
        key: bytes,
        *,
        progress_file: str | None = None,
        **options: Any,
    ) -> tuple[bytes, Any]:
        from ..dct_steganography import embed_in_dct

        output_format = options.get("dct_output_format", "png")
        color_mode = options.get("dct_color_mode", "color")
        quant_step = options.get("quant_step")
        jpeg_quality = options.get("jpeg_quality")
        max_dimension = options.get("max_dimension")
        return embed_in_dct(
            data, carrier, key, output_format, color_mode, progress_file,
            quant_step=quant_step, jpeg_quality=jpeg_quality, max_dimension=max_dimension,
        )

    def extract(
        self,
        carrier: bytes,
        key: bytes,
        *,
        progress_file: str | None = None,
        **options: Any,
    ) -> bytes | None:
        from ..dct_steganography import extract_from_dct

        quant_step = options.get("quant_step")
        try:
            return extract_from_dct(carrier, key, progress_file, quant_step=quant_step)
        except Exception:
            return None

    def calculate_capacity(self, carrier: bytes, **options: Any) -> int:
        from ..dct_steganography import calculate_dct_capacity

        info = calculate_dct_capacity(carrier)
        return info.usable_capacity_bytes
