package main

import (
	"fmt"
	"net/http"

	"golang.org/x/net/webdav"
	"imuslab.com/smb/driver/mod/smb"
	"imuslab.com/smb/driver/mod/util"
)

var config *smb.Config

func main() {
	Logger := func(r *http.Request, err error) {
		if err != nil {
		} else {
		}
	}

	pwd := util.PWDR()
	anchor1 := smb.NewAnchor("TestDir1", pwd)
	anchor2 := smb.NewAnchor("TestDir2", pwd)

	config = &smb.Config{
		Pwd: func(name string) (string, error) {
			if "name" == name || name == "apple" {
				return "pwd", nil
			}
			return "", fmt.Errorf("not found")
		},
		Tree: func(userName string) ([]*smb.Anchor, error) {
			anchorIPC := smb.NewAnchor(smb.NamedPipeShareName, pwd)
			return []*smb.Anchor{
				anchor1,
				anchor2,
				anchorIPC,
			}, nil
		},
		Handle: func(path string) *smb.Handler {
			return &smb.Handler{
				&webdav.Handler{
					Logger:     Logger,
					Prefix:     "/" + anchor1.Name + "/",
					FileSystem: webdav.Dir("/"),
					LockSystem: webdav.NewMemLS(),
				},
			}
		},
	}

	ser := smb.NewServer(config)
	go ser.Start(445)
	fmt.Scanln()
	fmt.Scanln()
	fmt.Scanln()

}

func init() {

}
