drop procedure if exists pr_signal_strength;

delimiter //

create procedure pr_signal_strength( in device_id int,
                                     in NetworkType varchar)
begin
        if device_id != 0 then
                select 'error: not implemented per device query' as 'message';
        elseif NetworkType == 'WIFI' then
                select 'Fetching wifi data (latitude,longitude,gps_accuracy,timestamp,wifi_bssid,wifi_frequency,wifi_channel,wifi_rssi_signal_strength)' as 'message';
                select device_latitude,device_longitude,device_position_accuracy,timestamp,wifi_bssid,wifi_frequency,wifi_channel,wifi_rssi
                from networkmonitor where  network_type=NetworkType;
        elseif NetworkType == 'mobile/LTE' or network_type == 'MOBILE/LTE' then
                select 'Fetching LTE data (latitude,longitude,gps_accuracy,timestamp,sim_operator,sim_mcc,sim_mnc,cell_signal_strength_dbm)' as 'message';
                select device_latitude,device_longitude,device_position_accuracy,timestamp,sim_operator,sim_mcc,sim_mnc,cell_signal_strength_dbm
                from networkmonitor where network_type=NetworkType and sim_state='READY';
        elseif NetworkType == 'MOBILE/HSPA' then
                select 'Fetching HSPA data (latitude,longitude,gps_accuracy,timestamp,sim_operator,sim_mcc,sim_mnc,cell_signal_strength_dbm)' as 'message';
                select device_latitude,device_longitude,device_position_accuracy,timestamp,sim_operator,sim_mcc,sim_mnc,cell_signal_strength_dbm
                from networkmonitor where network_type=NetworkType and sim_state='READY';
        elseif NetworkType == 'MOBILE/HSPA+' then
                select 'Fetching HSPA+ data (latitude,longitude,gps_accuracy,timestamp,sim_operator,sim_mcc,sim_mnc,cell_signal_strength_dbm)' as 'message';
                select device_latitude,device_longitude,device_position_accuracy,timestamp,sim_operator,sim_mcc,sim_mnc,cell_signal_strength_dbm
                from networkmonitor where network_type=NetworkType and sim_state='READY';
        end if;
end//

delimiter ;
