"""Describe command — set home zone description."""

from mudlib.commands import CommandDefinition, register
from mudlib.housing import save_home_zone
from mudlib.player import Player
from mudlib.zone import Zone


async def cmd_describe(player: Player, args: str) -> None:
    """Set the description for your home zone.

    Usage:
        describe <text>   — set your home zone description
        describe          — show current description
    """
    zone = player.location

    # Must be in a zone
    if not isinstance(zone, Zone):
        await player.send("You aren't anywhere.\r\n")
        return

    # Must be in own home zone
    if zone.name != player.home_zone:
        await player.send("You can only describe your own home zone.\r\n")
        return

    # No args — show current description
    if not args.strip():
        await player.send(f"Current description: {zone.description}\r\n")
        return

    # Set new description
    description = args.strip()
    if len(description) > 500:
        await player.send("Description too long (max 500 characters).\r\n")
        return
    zone.description = description
    save_home_zone(player.name, zone)

    await player.send(f"Home zone description set to: {zone.description}\r\n")


register(
    CommandDefinition(
        "describe",
        cmd_describe,
        help="Set your home zone description.",
    )
)
