#  Rubio - Rubika API library for python
#  Copyright (C) 2025-present Rubio <https://github.com/RubioTeam>
#  Github - https://github.com/RubioTeam/rubio.core


from __future__ import annotations

from typing import Optional, Union, BinaryIO
import rubio.core


class SendMusic:

    __slots__ = ()

    async def send_music(
        self: rubio.core.Client,
        chat_id: str,
        music: Union[str, bytes, BinaryIO],
        caption: Optional[str] = None,
        filename: Optional[str] = None,
        chat_keypad: Optional[rubio.core.types.Keypad] = None,
        inline_keypad: Optional[rubio.core.types.Keypad] = None,
        chat_keypad_type: Optional[rubio.core.enums.ChatKeypadType] = None,
        disable_notification: bool = False,
        reply_to_message_id: Optional[str] = None,
        parse_mode: Optional[Union[str, rubio.core.enums.ParseMode]] = None,
        auto_delete: Optional[int] = None,
        headers: Optional[dict] = None,
        proxy: Optional[str] = None,
        retries: Optional[int] = None,
        delay: Optional[float] = None,
        backoff: Optional[float] = None,
        max_delay: Optional[float] = None,
        timeout: Optional[float] = None,
        connect_timeout: Optional[float] = None,
        read_timeout: Optional[float] = None
    ) -> rubio.core.types.UMessage:
        """
        Send a music file to a chat on Rubika.

        This is a convenience wrapper around :meth:`send_file` specifically for sending
        music/audio files. Supports the same parameters as `send_file` including captions, keyboards,
        message parsing, auto-delete, and notification options.

        Note: Uses `FileType.FILE` for music files. Ensure the file format is supported by Rubika.

        Parameters:
            chat_id (str):
                The target chat ID where the music will be sent.

            music (Union[str, bytes, BinaryIO]):
                The music file to send. Can be:
                - Local file path (str)
                - HTTP/HTTPS URL (str)
                - Bytes or BinaryIO stream

            caption (Optional[str], default: None):
                Text caption for the music file.

            filename (Optional[str], default: None):
                Custom filename for the uploaded music file.

            chat_keypad (Optional[rubio.core.types.Keypad], default: None):
                Keypad to attach to the chat message.

            inline_keypad (Optional[rubio.core.types.Keypad], default: None):
                Keypad to attach inline with the message.

            chat_keypad_type (Optional[rubio.core.enums.ChatKeypadType], default: None):
                Type of chat keyboard (e.g., INLINE, REPLY).

            disable_notification (bool, default: False):
                If True, sends the message silently.

            reply_to_message_id (Optional[str], default: None):
                ID of a message to reply to.

            parse_mode (Optional[Union[str, rubio.core.enums.ParseMode]], default: None):
                Text formatting mode for the caption.

            auto_delete (Optional[int], default: None):
                Number of seconds after which the message will be automatically deleted.

            headers (Optional[dict], default: None):
                Optional HTTP headers for the upload request.

            proxy (Optional[str], default: None):
                Optional proxy URL to use for requests.

            retries (Optional[int], default: None):
                Number of retry attempts on request failure.

            delay (Optional[float], default: None):
                Initial delay between retries in seconds.

            backoff (Optional[float], default: None):
                Backoff multiplier applied after each retry.

            max_delay (Optional[float], default: None):
                Maximum delay between retries.

            timeout (Optional[float], default: None):
                Total request timeout in seconds.

            connect_timeout (Optional[float], default: None):
                Timeout for establishing the connection.

            read_timeout (Optional[float], default: None):
                Timeout for reading the response data.

        Returns:
            rubio.core.types.UMessage:
                The message object representing the sent music file.

        Example:
        .. code-block:: python
            # Send music from local file
            message = await client.send_music(
                chat_id="123456",
                music="path/to/song.mp3",
                caption="Listen to this track!",
                auto_delete=120
            )

            # Send music from URL
            message = await client.send_music(
                chat_id="789012",
                music="https://example.com/song.mp3",
                caption="Music from the web"
            )

            # Send music as bytes
            with open("song.mp3", "rb") as f:
                music_bytes = f.read()
            message = await client.send_music(
                chat_id="345678",
                music=music_bytes,
                filename="custom_name.mp3"
            )
        """
        return await self.send_file(
            chat_id,
            music,
            caption,
            filename,
            rubio.core.enums.FileType.FILE,
            chat_keypad,
            inline_keypad,
            chat_keypad_type,
            disable_notification,
            reply_to_message_id,
            parse_mode,
            auto_delete,
            headers,
            proxy,
            retries,
            delay,
            backoff,
            max_delay,
            timeout,
            connect_timeout,
            read_timeout
        )