use crate::plugin::{{plugin}}::{{model_a}}::{{model}};
use json::JsonValue;
use br_plugin::Response;
use br_plugin::action::Action;
use br_plugin::model::Model;
use crate::plugin::check_auth;

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

impl Action for {{action}} {
    fn author(&mut self) -> &'static str {
        return "";
    }
    fn title(&mut self) -> &'static str { "{{title}}" }
    fn api(&mut self) -> &'static str { "{{api}}" }
    fn token(&mut self) -> bool { true }
    fn params(&mut self) -> JsonValue { return self.model.table_fields(); }
    fn index(&mut self, header: JsonValue, request: JsonValue) -> Response {
        let t=self.model.fields_name_list(vec![]);
        let fields=t.iter().map(|x|x.as_str()).collect::<Vec<&str>>();
        let mut data = self.model.tables(
            header.clone(),
            request.clone(),
            fields,
            vec![],
            vec![],
        );

        let btn_all: Vec<JsonValue> = vec![];
        let btn_ids: Vec<JsonValue> = vec![];
        let btn_one: Vec<JsonValue> = vec![];


        let btn_all = check_auth(btn_all, header.clone());
        let btn_ids = check_auth(btn_ids, header.clone());
        let btn_one = check_auth(btn_one, header.clone());

        data["btn_all"] = btn_all.into();
        data["btn_ids"] = btn_ids.into();
        data["btn_one"] = btn_one.into();

        return self.success(data, "成功");
    }
}