<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def filename(self, fname, timestep=None, suffix='', force_legacy=False):
 """Return name of StagYY output file. Args: fname (str):
 name stem. timestep (int):
 snapshot number, set to None if this is not relevant. suffix (str):
 optional suffix of file name. force_legacy (bool):
 force returning the legacy output path. Returns: :class:`pathlib.Path`: the path of the output file constructed with the provided segments. """

        if timestep is not None:
            fname += '{:05d}'.format(timestep)
        fname += suffix
        if not force_legacy and self.hdf5:
            fpath = self.hdf5 / fname
        else:
            fpath = self.par['ioin']['output_file_stem'] + '_' + fname
            fpath = self.path / fpath
        return fpath