// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use anyhow::anyhow;
use bumble::{
    adv::{AdvertisementDataBuilder, CommonDataType},
    wrapper::{
        device::Device,
        logging::{bumble_env_logging_level, py_logging_basic_config},
        transport::Transport,
    },
};
use clap::Parser as _;
use pyo3::PyResult;
use rand::Rng;
use std::path;

#[pyo3_asyncio::tokio::main]
async fn main() -> PyResult<()> {
    env_logger::builder()
        .filter_level(log::LevelFilter::Info)
        .init();

    let cli = Cli::parse();

    if cli.log_hci {
        py_logging_basic_config(bumble_env_logging_level("DEBUG"))?;
    }

    let transport = Transport::open(cli.transport).await?;

    let mut device = Device::from_config_file_with_hci(
        &cli.device_config,
        transport.source()?,
        transport.sink()?,
    )?;

    let mut adv_data = AdvertisementDataBuilder::new();

    adv_data
        .append(
            CommonDataType::CompleteLocalName,
            "Bumble from Rust".as_bytes(),
        )
        .map_err(|e| anyhow!(e))?;

    // Randomized TX power
    adv_data
        .append(
            CommonDataType::TxPowerLevel,
            &[rand::thread_rng().gen_range(-100_i8..=20) as u8],
        )
        .map_err(|e| anyhow!(e))?;

    device.set_advertising_data(adv_data)?;
    device.power_on().await?;

    println!("Advertising...");
    device.start_advertising(true).await?;

    // wait until user kills the process
    tokio::signal::ctrl_c().await?;

    println!("Stopping...");
    device.stop_advertising().await?;

    Ok(())
}

#[derive(clap::Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
    /// Bumble device config.
    ///
    /// See, for instance, `examples/device1.json` in the Python project.
    #[arg(long)]
    device_config: path::PathBuf,
    /// Bumble transport spec.
    ///
    /// <https://google.github.io/bumble/transports/index.html>
    #[arg(long)]
    transport: String,

    /// Log HCI commands
    #[arg(long)]
    log_hci: bool,
}
