// Tauri 鎼存梻鏁ょ粙瀣碍娑撹绨遍弬鍥︽ - 濡€虫健閸栨牜澧楅張?
// 娴犲懓绀嬬拹锝喣侀崸妤€锛愰弰搴℃嫲API濞夈劌鍞?

pub mod models;
pub mod database;
pub mod auth;
pub mod products;
pub mod customers;
pub mod suppliers;
pub mod sales;
pub mod purchases;
pub mod inventory;
pub mod statistics;
pub mod print;
pub mod billing;
pub mod warehouses;
pub mod locations;
pub mod transfers;
pub mod packages;
pub mod assembly;
pub mod excel;
pub mod invoices;
pub mod returns;
pub mod payments;
pub mod categories;
pub mod warehouse_ops;
pub mod error_util;
pub mod permissions;
pub mod operation_logs;
pub mod backup;
pub mod system_config;
pub mod documents;
pub mod license;
pub mod server;


#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_opener::init())
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_fs::init())
        .setup(|_app| {
            // database init is now lazy - called by frontend when standalone mode selected
            Ok(())
        })
        .invoke_handler(tauri::generate_handler![
            // 閻劍鍩涚拋銈堢槈
            license::get_machine_code,
            license::activate_license,
            license::check_license,
            
            auth::login,
            auth::get_users,
            auth::add_user,
            auth::delete_user,
            auth::change_password,
            auth::admin_reset_password,
            auth::get_accounts,
            // 閸熷棗鎼х粻锛勬倞
            products::add_product,
            products::get_or_create_product,
            products::get_products,
            products::update_product,
            products::delete_product,
            products::batch_delete_products,
            products::update_product_image,
            products::save_product_image,
            products::add_product_spec,
            products::get_product_specs,
            products::delete_product_spec,
            // 鐎广垺鍩涚粻锛勬倞
            customers::add_customer,
            customers::get_customers,
            customers::update_customer,
            customers::delete_customer,
            // 娓氭稑绨查崯鍡欘吀閻?
            suppliers::add_supplier,
            suppliers::get_suppliers,
            suppliers::update_supplier,
            suppliers::delete_supplier,
            // 闁库偓閸烆喚顓搁悶?
            sales::create_sale_order,
            sales::batch_create_sale_orders,
            sales::get_sale_orders,
            sales::update_sale_order_status,
            sales::delete_sale_order,
            sales::toggle_sale_invoice,
            sales::get_sale_order_items,
            // 闁插洩鍠樼粻锛勬倞
            purchases::create_purchase_order,
            purchases::get_purchase_orders,
            purchases::update_purchase_order_status,
            purchases::delete_purchase_order,
            purchases::toggle_purchase_invoice,
            purchases::get_purchase_order_items,
            // 鎼存挸鐡ㄧ粻锛勬倞
            inventory::get_inventory,
            inventory::get_inventory_records,
            inventory::adjust_inventory,
            inventory::get_warehouse_stock,
            // 缂佺喕顓搁崚鍡樼€?
            statistics::get_statistics,
            // 閹垫挸宓冨Ο鈩冩緲缁狅紕鎮?
            print::add_print_template,
            print::get_print_templates,
            print::get_print_templates_by_type,
            print::update_print_template,
            print::delete_print_template,
            print::set_default_print_template,
            print::get_default_print_template,
            // 鎼存梹鏁规惔鏂剧帛鐠愶箑宕?
            billing::create_billing,
            billing::update_billing_payment,
            billing::update_billing,
            billing::auto_create_billing,
            billing::get_billings,
            billing::delete_billing,
            billing::generate_billing_pdf,
            billing::get_customer_statement,
            billing::get_supplier_statement,
            billing::get_party_balance,
            // 娴犳挸绨辩粻锛勬倞
            warehouses::add_warehouse,
            warehouses::get_warehouses,
            warehouses::update_warehouse,
            warehouses::delete_warehouse,
            // 鎼存挷缍呯粻锛勬倞
            locations::add_location,
            locations::get_locations,
            locations::get_all_locations,
            locations::debug_locations,
            locations::update_location,
            locations::delete_location,
            // 鎼存挸鐡ㄧ拫鍐╁
            transfers::create_transfer_order,
            transfers::get_transfer_orders,
            transfers::get_transfer_order_items,
            transfers::delete_transfer_order,
            // 閸栧懍娆㈢粻锛勬倞
            packages::add_product_package,
            packages::get_product_packages,
            packages::get_all_packages,
            packages::delete_product_package,
            // 娴溠冩惂缂佸嫯顥婇幏鍡楀瀻
            assembly::create_assembly_record,
            assembly::get_assembly_records,
            assembly::delete_assembly_record,
            // Excel 鐎电厧鍙嗙€电厧鍤?
            excel::export_products,
            excel::import_products,
            excel::export_sale_orders,
            excel::export_purchase_orders,
            excel::export_customers,
            excel::export_suppliers,
            excel::import_customers,
            excel::import_suppliers,
            excel::import_sale_orders,
            excel::import_purchase_orders,
            // 閹靛綊鍣洪幙宥勭稊
            products::batch_add_products,
            products::update_product_spec,
            // 閸欐垹銈ㄧ粻锛勬倞
            invoices::add_invoice,
            invoices::get_invoices,
            invoices::delete_invoice,
            // 闁偓鐠愌咁吀閻?
            returns::create_return_order,
            returns::get_return_orders,
            returns::get_return_order_items,
            returns::delete_return_order,
            // 鏉╂ɑ顑欑拋鏉跨秿
            payments::add_payment_record,
            payments::get_payment_records,
            payments::delete_payment_record,
            // 缁鍩嗙粻锛勬倞
            categories::add_category,
            categories::get_categories,
            categories::delete_category,
            // 娴犳挸绨遍幙宥勭稊
            warehouse_ops::stock_in,
            warehouse_ops::stock_out,
            warehouse_ops::stock_count,
            warehouse_ops::batch_stock_in,
            warehouse_ops::batch_stock_out,
            // 閸熷棗鎼ч弬鍥ㄣ€?
            documents::save_product_document,
            documents::get_product_documents,
            documents::delete_product_document,
            documents::read_file_base64,
            // 鐠併垹宕熸径鍥ㄦ暈缂傛牞绶?
            sales::update_sale_order_remark,
            purchases::update_purchase_order_remark,
            // 缁崵绮洪柊宥囩枂
            system_config::get_system_config,
            system_config::set_system_config,
            system_config::get_all_system_configs,
            // 閹垮秳缍旈弮銉ョ箶
            operation_logs::add_operation_log,
            operation_logs::get_operation_logs,
            operation_logs::clear_operation_logs,
            backup::backup_database,
            backup::save_backup_to,
            backup::list_backups,
            backup::restore_database,
            backup::restore_database_from,
            backup::get_last_backup_path,
            backup::restart_app,
            backup::check_and_run_auto_backup,
            backup::get_auto_backup_config,
            // 鐟欐帟澹婇弶鍐
            permissions::get_role_permissions,
            permissions::set_role_permission,
            // 鎼存挸鐡ㄧ紒鐔活吀婢х偛宸?
            statistics::get_statistics_detail,
            statistics::global_search,
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
