use lapin::options::QueueDeclareOptions;

/// QueueSettings for declaring RabbitMq queue within consumer & publisher
pub struct QueueSettings {
    pub name: String,
    pub passive: bool,
    pub durable: bool,
    pub exclusive: bool,
    pub auto_delete: bool,
    pub nowait: bool,
}

impl QueueSettings {
    /// Default settings with all fields set to `false`
    pub fn new(name: String) -> QueueSettings {
        QueueSettings {
            name,
            passive: false,
            durable: false,
            exclusive: false,
            auto_delete: false,
            nowait: false,
        }
    }

    /// Default settings with all fields set to `false` except durable
    pub fn new_durable(name: String) -> QueueSettings {
        QueueSettings {
            name,
            passive: false,
            durable: true,
            exclusive: false,
            auto_delete: false,
            nowait: false,
        }
    }
}

impl From<&QueueSettings> for QueueDeclareOptions {
    fn from(settings: &QueueSettings) -> Self {
        QueueDeclareOptions {
            passive: settings.passive,
            durable: settings.durable,
            exclusive: settings.exclusive,
            auto_delete: settings.auto_delete,
            nowait: settings.nowait,
        }
    }
}
