#!/usr/bin/python3
import os, pathlib, sys, urllib.parse
root = pathlib.Path(os.environ['HOME'])
assert root.is_absolute() and (root / '.flea-test-sandbox').is_file()
files = root / 'data/Trash/files'
names = sorted(p.name for p in files.iterdir() if p.is_file())
args = sys.argv[1:]
def uri(name): return 'trash:///' + urllib.parse.quote(name)
# As gio 2.90.1 does, an item with no record, or a record with no Path line, lists with no orig-path.
def described(name):
    record = root / 'data/Trash/info' / (name + '.trashinfo')
    return record.is_file() and 'Path=' in record.read_text()
if args[0] == 'list':
    requested = args[args.index('-a') + 1].split(',') if '-a' in args else []
    for name in names:
        attributes = []
        if 'standard::target-uri' in requested:
            attributes.append('standard::target-uri=' + (files / name).as_uri())
        if 'trash::deletion-date' in requested:
            attributes.append('trash::deletion-date=2026-10-18T09:00:00')
        if 'trash::orig-path' in requested and described(name):
            attributes.append('trash::orig-path=' + str(root / 'original' / name))
        print(uri(name) + '\t1\t(regular)\t' + ' '.join(attributes))
elif args[0] == 'info':
    for target in [arg for arg in args[1:] if arg.startswith('trash:///')]:
        print('uri: ' + target)
        name = urllib.parse.unquote(urllib.parse.urlsplit(target).path).lstrip('/')
        path = files / name
        meta = path.lstat()
        print('  standard::size: ' + str(meta.st_size))
        print('  standard::type: 1')
        print('  standard::icon: image-x-generic')
        print('  standard::target-uri: ' + path.as_uri())
        print('  trash::deletion-date: 2026-10-18T09:00:00')
        print('  id::file: l' + str(meta.st_dev) + ':' + str(meta.st_ino))
        print('  id::filesystem: local')
else:
    raise SystemExit('Unexpected gio request: ' + repr(args))
