package sys

import (
	experimentalsys 
	
	
)

// compile-time check to ensure lazyDir implements sys.File.
var _ experimentalsys.File = (*lazyDir)(nil)

type lazyDir struct {
	experimentalsys.DirFile

	fs experimentalsys.FS
	f  experimentalsys.File
}

// Dev implements the same method as documented on sys.File
func ( *lazyDir) () (uint64, experimentalsys.Errno) {
	if ,  := .file(); ! {
		return 0, experimentalsys.EBADF
	} else {
		return .Dev()
	}
}

// Ino implements the same method as documented on sys.File
func ( *lazyDir) () (sys.Inode, experimentalsys.Errno) {
	if ,  := .file(); ! {
		return 0, experimentalsys.EBADF
	} else {
		return .Ino()
	}
}

// IsDir implements the same method as documented on sys.File
func ( *lazyDir) () (bool, experimentalsys.Errno) {
	// Note: we don't return a constant because we don't know if this is really
	// backed by a dir, until the first call.
	if ,  := .file(); ! {
		return false, experimentalsys.EBADF
	} else {
		return .IsDir()
	}
}

// IsAppend implements the same method as documented on sys.File
func ( *lazyDir) () bool {
	return false
}

// SetAppend implements the same method as documented on sys.File
func ( *lazyDir) (bool) experimentalsys.Errno {
	return experimentalsys.EISDIR
}

// Seek implements the same method as documented on sys.File
func ( *lazyDir) ( int64,  int) ( int64,  experimentalsys.Errno) {
	if ,  := .file(); ! {
		return 0, experimentalsys.EBADF
	} else {
		return .Seek(, )
	}
}

// Stat implements the same method as documented on sys.File
func ( *lazyDir) () (sys.Stat_t, experimentalsys.Errno) {
	if ,  := .file(); ! {
		return sys.Stat_t{}, experimentalsys.EBADF
	} else {
		return .Stat()
	}
}

// Readdir implements the same method as documented on sys.File
func ( *lazyDir) ( int) ( []experimentalsys.Dirent,  experimentalsys.Errno) {
	if ,  := .file(); ! {
		return nil, experimentalsys.EBADF
	} else {
		return .Readdir()
	}
}

// Sync implements the same method as documented on sys.File
func ( *lazyDir) () experimentalsys.Errno {
	if ,  := .file(); ! {
		return experimentalsys.EBADF
	} else {
		return .Sync()
	}
}

// Datasync implements the same method as documented on sys.File
func ( *lazyDir) () experimentalsys.Errno {
	if ,  := .file(); ! {
		return experimentalsys.EBADF
	} else {
		return .Datasync()
	}
}

// Utimens implements the same method as documented on sys.File
func ( *lazyDir) (,  int64) experimentalsys.Errno {
	if ,  := .file(); ! {
		return experimentalsys.EBADF
	} else {
		return .Utimens(, )
	}
}

// file returns the underlying file or false if it doesn't exist.
func ( *lazyDir) () (experimentalsys.File, bool) {
	if  := .f; .f != nil {
		return , true
	}
	var  experimentalsys.Errno
	.f,  = .fs.OpenFile(".", experimentalsys.O_RDONLY, 0)
	switch  {
	case 0:
		return .f, true
	case experimentalsys.ENOENT:
		return nil, false
	default:
		panic() // unexpected
	}
}

// Close implements fs.File
func ( *lazyDir) () experimentalsys.Errno {
	 := .f
	if  == nil {
		return 0 // never opened
	}
	return .Close()
}

// IsNonblock implements the same method as documented on fsapi.File
func ( *lazyDir) () bool {
	return false
}

// SetNonblock implements the same method as documented on fsapi.File
func ( *lazyDir) (bool) experimentalsys.Errno {
	return experimentalsys.EISDIR
}

// Poll implements the same method as documented on fsapi.File
func ( *lazyDir) (fsapi.Pflag, int32) ( bool,  experimentalsys.Errno) {
	return false, experimentalsys.ENOSYS
}