use br_fields::Field;
use json::{JsonValue, object};
use crate::{Action, Model};
use crate::test::test::add::TestTestAdd;
use crate::test::test::delete::TestTestDelete;
use crate::test::test::get::TestTestGet;
use crate::test::test::put::TestTestPut;
use crate::test::test::select::TestTestSelect;
use crate::test::test::table::TestTestTable;

pub struct TestTest {}

impl Model for TestTest {
    fn title(&mut self) -> &'static str { "测试模块" }
    fn table(&mut self) -> &'static str { "test_test" }

    fn fields(&mut self) -> JsonValue {
        let mut fields = object! {};
        fields[self.primary_key()] = br_fields::str::Key::new(true, self.primary_key(), "ID", 20).field();
        fields["str"] = br_fields::str::Str::new(true, "str", "字符串", 15, "").field();
        fields["color"] = br_fields::str::Color::new(true, "color", "颜色", "000000").field();
        fields["email"] = br_fields::str::Email::new(true, "email", "邮件", "").field();
        fields["pass"] = br_fields::str::Pass::new(true, "pass", "密码", 64, "").field();
        fields["tel"] = br_fields::str::Tel::new(true, "tel", "电话", "").field();
        fields["int"] = br_fields::int::Int::new(true, "int", "整数", 20, 0).field();
        fields["switch"] = br_fields::int::Switch::new(true, "switch", "开关", 1).field();
        fields["float"] = br_fields::float::Float::new(true, "float", "小数", 9, 2, 0.0).field();
        fields["timestamp"] = br_fields::datetime::Timestamp::new(true, "timestamp", "时间戳", 0, 0.0).field();
        fields["datetime"] = br_fields::datetime::Datetime::new(true, "datetime", "日期时间", "").field();
        fields["date"] = br_fields::datetime::Date::new(true, "date", "日期", "").field();
        fields["time"] = br_fields::datetime::Time::new(true, "time", "时间", "").field();
        fields["year"] = br_fields::datetime::Year::new(true, "year", "年", 0).field();
        fields["radio"] = br_fields::select::Radio::new(true, "radio", "单选", vec!["男士", "女士"], "男士").field();
        fields["file"] = br_fields::text::File::new(true, "file", "文件", 1, false, 0, vec![]).field();
        fields["text"] = br_fields::text::Text::new(true, "text", "文本", "").field();
        fields["url"] = br_fields::text::Url::new(true, "url", "链接", "").field();
        fields["json"] = br_fields::text::Json::new(true, "json", "json", object! {}).field();
        fields["selects"] = br_fields::select::Select::new(true, "selects", "多选", vec!["男士", "女士"], vec!["男士"]).field();
        fields["tables"] = br_fields::text::Table::new(true, "tables", "关联", "dict", vec!["name", "code"], "").field();
        return fields;
    }
    fn action(&mut self, name: &str) -> Box<dyn Action> {
        match name {
            "table" => Box::new(TestTestTable { model: TestTest {} }),
            "add" => Box::new(TestTestAdd { model: TestTest {} }),
            "delete" => Box::new(TestTestDelete { model: TestTest {} }),
            "get" => Box::new(TestTestGet { model: TestTest {} }),
            "put" => Box::new(TestTestPut { model: TestTest {} }),
            "select" => Box::new(TestTestSelect { model: TestTest {} }),
            _ => Box::new(TestTestTable { model: TestTest {} })
        }
    }
}

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