package filemanager

// FileItem represents a file or directory in VueFinder format.
type FileItem struct {
	Type         string `json:"type"`          // "dir" or "file"
	Path         string `json:"path"`          // "server://relative/path"
	Basename     string `json:"basename"`      // filename.ext
	Extension    string `json:"extension"`     // "ext" or "" for dirs
	Storage      string `json:"storage"`       // always "server"
	FileSize     int64  `json:"file_size"`     // bytes, 0 for dirs
	LastModified string `json:"last_modified"` // "2006-01-02 15:04:05"
}

// ListResponse is the VueFinder index/directory response.
type ListResponse struct {
	Adapter  string     `json:"adapter"`  // always "local"
	Storages []string   `json:"storages"` // ["server"]
	Dirname  string     `json:"dirname"`  // "server://current/path"
	Files    []FileItem `json:"files"`    // directory contents
}

// SearchResponse is the VueFinder search response.
type SearchResponse struct {
	Adapter  string     `json:"adapter"`
	Storages []string   `json:"storages"`
	Dirname  string     `json:"dirname"`
	Files    []FileItem `json:"files"`
}

// NatsRequest is the NATS request payload sent by the backend for file manager operations.
type NatsRequest struct {
	Func        string   `json:"func"`                 // "fm_list", "fm_delete", etc.
	Path        string   `json:"path"`                 // VueFinder storage path, e.g. "server://cfg"
	Items       []string `json:"items,omitempty"`      // items to delete/move/copy (relative storage paths)
	Name        string   `json:"name,omitempty"`       // new name for rename/create
	Destination string   `json:"destination,omitempty"` // destination storage path for move/copy
	Filter      string   `json:"filter,omitempty"`     // search filter string
	Content     string   `json:"content,omitempty"`    // file content (save) or base64-encoded data (upload)
	Filename    string   `json:"filename,omitempty"`   // original filename for upload
}

// NatsResponse wraps every response sent back to the backend.
type NatsResponse struct {
	Success bool        `json:"success"`
	Error   string      `json:"error,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

// Function name constants matching what the backend sends.
const (
	FuncList         = "fm_list"
	FuncDelete       = "fm_delete"
	FuncRename       = "fm_rename"
	FuncCopy         = "fm_copy"
	FuncMove         = "fm_move"
	FuncCreateFolder = "fm_mkdir"
	FuncCreateFile   = "fm_mkfile"
	FuncSearch       = "fm_search"
	FuncPreview      = "fm_preview"
	FuncSave         = "fm_save"
	FuncUpload       = "fm_upload"
)
