use std::path::PathBuf;
use dav_server::{DavHandler, localfs::LocalFs, fakels::FakeLs};

pub struct MarkBaseWebDAV {
    user_id: String,
    db_path: PathBuf,
}

impl MarkBaseWebDAV {
    pub fn new(user_id: String, db_path: PathBuf) -> Self {
        MarkBaseWebDAV { user_id, db_path }
    }
    
    pub fn create_handler(&self) -> DavHandler {
        let webdav_dir = format!("data/webdav/{}/", self.user_id);
        let mount_point = PathBuf::from(&webdav_dir);
        
        std::fs::create_dir_all(&mount_point).expect("Failed to create WebDAV directory");
        
        DavHandler::builder()
            .filesystem(LocalFs::new(&mount_point, false, false, false))
            .locksystem(FakeLs::new())
            .strip_prefix("/webdav")
            .build_handler()
    }
}
