import click


def common_mqtt_options(func):
    """Supply common mqtt gateway options."""
    func = click.option(
        "-r",
        "--retain",
        is_flag=True,
        default=False,
        help="Turn on retain on published messages at broker.",
    )(func)
    func = click.option(
        "--out-prefix",
        default="mygateway1-in",
        show_default=True,
        help="Topic prefix for outgoing messages.",
    )(func)
    func = click.option(
        "--in-prefix",
        default="mygateway1-out",
        show_default=True,
        help="Topic prefix for incoming messages.",
    )(func)
    func = click.option(
        "-p",
        "--port",
        default=1883,
        show_default=True,
        type=int,
        help="MQTT port of the connection.",
    )(func)
    func = click.option("-b", "--broker", required=True, help="MQTT broker address.")(
        func
    )
    return func