// Copyright (C) 2022 Marius Schellenberger

package sftp

import (
	"io/fs"

	"github.com/pkg/sftp"
)

type file struct {
	*sftp.File
	fs *FS
}

func (f *file) ReadDir(_ int) (d []fs.DirEntry, err error) {
	list, err := f.Readdir(0)
	if err != nil {
		return
	}
	d = make([]fs.DirEntry, len(list))
	for i, v := range list {
		d[i] = fs.FileInfoToDirEntry(v)
	}
	return
}

func (f *file) Readdir(_ int) ([]fs.FileInfo, error) {
	return f.fs.client.ReadDir(f.Name())
}

func (file) Fd() uintptr {
	return 0
}
