########## 
##########
# Set equations to track biomass in each population 
##########
##########
# AUTHOR: Cole B. Brookson
# DATE OF CREATION: 2021-06-25
##########
##########

# set up =======================================================================

using DifferentialEquations
include("./src/eqn_component_functions.jl")
include("./src/species_list_creation.jl")
include("./src/network_metrics.jl")

"""
    check_extinctions!(x)

Check if any species have low enough abundance to warrent extinction - if so, 
remove them from the array of abundances right away.
"""
function check_extinctions!(x::Array)
    for i in 1:length(x)
        if x[i] < 1.0e-30
            x[i] = 0
        end 
    end 
    return x 
end 



"""
biomass!(dx, x, p, t)

Calling biomass functions, create the actual equation for each species, to be 
passed to the simulation. 
"""
function biomass!(dx, x, p, t)
    for i in 1:size(species_list, 1)
        dx[i] = growth_rate(i, species_list, x) + 
                biomass_gain(species_list, network, x, 2, i) -
                biomass_loss(species_list, network, x, 2, i) -
                mortality_change(i, x)
    end 
end 

function starting_eq_sims(
    species_list::Array,
    network::Array
    )
        
    #  allocate memory
    dx = zeros(50)

    # save all initial parameters (maybe a seaprate object)

    # sims 

function perturbation_simulation(
    species_list:::Array,
    network::Array,
    type_of_perturbation::String,
    x::Array
    )

# pre-allocate memory for the objects we want to save from the time series 
# save initial parameters
# sim from the starting biomass out to 5000 - save that point 
# ^ maybe every 10 points stop it and check for extinction in any of them 
# ^ also, add a component to the species_list to keep track of alive (1) or 
#    extinct (0)
# check the shape of the web at that point & save 
# sim 10 at a time, check for extinctions, check for perturbation ,
#    get the parameters again 

