// Copyright (C) 2022 Marius Schellenberger

package provider

import (
	"errors"
	"io"
	"io/fs"
	"os"
)

var ErrFstat = errors.New("fstat not supported")

type FS interface {
	Stat(string) (fs.FileInfo, error)
	Remove(string) error
	Open(string) (File, error)
	OpenFile(string, int, os.FileMode) (File, error)
	MkdirAll(string, os.FileMode) error
	Root() string
	Fstat(uintptr) (int64, error)
	Close() error
}

type walk struct {
	fs FS
}

func (w *walk) Open(p string) (fs.File, error) {
	return w.fs.Open(p)
}

func WalkFS(fs FS) fs.FS {
	return &walk{fs}
}

type File interface {
	io.Reader
	io.ReaderAt
	io.Writer
	io.WriterAt
	io.Seeker
	io.Closer
	Name() string
	Stat() (fs.FileInfo, error)
	Truncate(int64) error
	Sync() error
	Fd() uintptr
	ReadDir(int) ([]fs.DirEntry, error)
	Readdir(int) ([]fs.FileInfo, error)
}
