use json::{JsonValue, object};
use br_plugin::addon::AddonTemp;
use br_plugin::model::{Model, ModelTemp};
use br_plugin::action::{Action, ActionTemp};

pub struct {{model}} {
    pub addon: {{addon}}
}

impl Model for {{model}} {
    fn title(&mut self) -> &'static str { "{{title}}"}
    fn table(&mut self) -> &'static str { "{{plugin_model}}"}
    fn unique(&mut self) -> Vec<&'static str> {
        vec![]
    }
    fn index(&mut self) -> Vec<Vec<&'static str>> {
        vec![]
    }
    fn fields(&mut self) -> JsonValue {
        let fields = object! {};
        return fields;
    }
    fn action(&mut self, name: &str) -> Box<dyn Action> {
        match name {
            "table" => Box::new({{model}}Table { model: {{model}} {addon: {{addon}} {}} }),
            "add" => Box::new({{model}}Add { model: {{model}} {addon: {{addon}} {}} }),
            "del" => Box::new({{model}}Del { model: {{model}} {addon: {{addon}} {}} }),
            "get" => Box::new({{model}}Get { model: {{model}} {addon: {{addon}} {}} }),
            "put" => Box::new({{model}}Put { model: {{model}} {addon: {{addon}} {}} }),
            "select" => Box::new({{model}}Select { model: {{model}} {addon: {{addon}} {}} }),
            _ => Box::new(ActionTemp { model: ModelTemp { addon: AddonTemp {} } }),
        }
    }
}

pub mod table;
pub mod add;
pub mod del;
pub mod get;
pub mod put;
pub mod select;