package session

import (
	
	
	

	
)

// FileStorage implements SessionStorage for file system as file
// stored in Path.
type FileStorage struct {
	Path string
	mux  sync.Mutex
}

// LoadSession loads session from file.
func ( *FileStorage) ( context.Context) ([]byte, error) {
	if  == nil {
		return nil, errors.New("nil session storage is invalid")
	}

	.mux.Lock()
	defer .mux.Unlock()

	,  := os.ReadFile(.Path)
	if os.IsNotExist() {
		return nil, ErrNotFound
	}
	if  != nil {
		return nil, errors.Wrap(, "read")
	}

	return , nil
}

// StoreSession stores session to file.
func ( *FileStorage) ( context.Context,  []byte) error {
	if  == nil {
		return errors.New("nil session storage is invalid")
	}

	.mux.Lock()
	defer .mux.Unlock()
	// TODO(tdakkota): use robustio/renameio?
	return os.WriteFile(.Path, , 0600)
}