use json::{JsonValue, object};
use br_addon::action::{Action, InterfaceType};
use br_addon::module::Module;
use br_addon::request::Request;
use br_addon::ApiResponse;

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

impl Action for {{action}} {
    fn title(&self) -> &'static str { "{{title}}" }
    fn tags(&self) -> &'static [&'static str] {
        &[]
    }

    fn interface_type(&self) -> InterfaceType {
        InterfaceType::MENU
    }
    fn params(&mut self) -> JsonValue {
        self.params_table_list(object! {})
    }
    fn index(&mut self, request: Request) -> ApiResponse {
        let fields = self.module.fields().clone();
        let table_name = self.module._table_name();
        let mut table_info = self.table_list(
            request.body.clone(),
            table_name,
            fields.clone(),
            vec![],
            vec![],
            vec![],
            vec![],
        );

        // table_info["btn_all"]=vec![].into();
        // table_info["btn_api"]=vec![].into();
        // table_info["btn_ids"]=vec![].into();

        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, "获取成功")
    }
}