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

#[derive(Debug, Clone)]
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::BTN}
    fn params(&mut self) -> JsonValue {
        let params = object! {};
        params
    }

    fn index(&mut self, request: Request) -> ApiResponse {
        let data = self.tools().db.table(self.module._table_name()).insert(request.body);
        if data.is_empty() {
            return ApiResponse::fail(122554, "添加失败");
        }
        ApiResponse::success(data, "添加成功")
    }
}