package udisks

import (
	"fmt"
)

// Mount mounts a filesystem and returns the mount point chosen by udisks2.
func (c *Client) Mount(dev *BlockDevice) (string, error) {
	obj := c.conn.Object(busName, dev.ObjectPath)

	var mountpoint string
	err := obj.Call(ifaceFilesystem+".Mount", 0, noOptions()).Store(&mountpoint)
	if err != nil {
		return "", fmt.Errorf("mounting %s: %w", dev.DevicePath, err)
	}
	return mountpoint, nil
}

// Unmount unmounts a filesystem.
func (c *Client) Unmount(dev *BlockDevice) error {
	obj := c.conn.Object(busName, dev.ObjectPath)
	return obj.Call(ifaceFilesystem+".Unmount", 0, noOptions()).Err
}
