use crate::plugin::{{plugin}}::{{model_a}}::{{model}};
use br_addon::action::{Action, BtnColor, BtnType, InterfaceType};
use br_addon::module::Module;
use br_addon::request::Request;
use br_addon::ApiResponse;
use json::{object, JsonValue};

pub struct {{action}} {
    pub module: {{model}},
}

impl Action for {{action}} {
    fn author(&self) -> &'static str {
       ""
    }
    fn title(&self) -> &'static str { "{{title}}" }
    fn tags(&self) -> &'static [&'static str] { &[] }
    fn interface_type(&self) -> InterfaceType { InterfaceType::MENU }
    fn icon(&self) -> &'static str { "" }

    fn params(&mut self) -> JsonValue { self.params_table_tree(object! {}) }
    fn index(&mut self, mut request: Request) -> ApiResponse {
         let fields = self.module.fields().clone();
         let table_name = self.module._table_name();

        let table_info = self.table_tree(
            request.body.clone(),
            table_name,
            table_name,
            "name",
            fields.clone(),
            vec![],
            vec![],
            vec![],
            vec![],
        );

        //table_info["btn_all"].push().unwrap();
        //table_info["btn_api"].push().unwrap();
        //table_info["btn_ids"].push().unwrap();

        table_info["btn_all"] = check_auth(table_info["btn_all"].clone(), request.clone());
        table_info["btn_api"] = check_auth(table_info["btn_api"].clone(), request.clone());
        table_info["btn_ids"] = check_auth(table_info["btn_ids"].clone(), request.clone());

        ApiResponse::success(table_info, "获取成功")
    }
}