<?php

/*
 * This file is a part of the NeimheadhBootstrapBundle project.
 *
 * (c) 2017 by Neimheadh
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Neimheadh\Bundle\CodeManipulationBundle\Model\File;

use Symfony\Component\Filesystem\Exception\FileNotFoundException;
use Symfony\Component\Filesystem\Exception\IOException;

/**
 * The files models interface.
 *
 * @author Neimheadh <contact@neimheadh.fr>
 */
interface FileInterface
{

    /**
     * Get path.
     *
     * @return string
     */
    public function getPath();

    /**
     * Set path.
     *
     * @param string $path
     *            The file path.
     * @return \Neimheadh\Bundle\CodeManipulationBundle\Model\File\FileInterface
     */
    public function setPath(string $path);

    /**
     * Get access mode.
     *
     * @return string
     */
    public function getAccessMode();

    /**
     * Set access mode.
     *
     * @param string $accessMode
     *            The access mode.
     * @return \Neimheadh\Bundle\CodeManipulationBundle\Model\File\FileInterface
     */
    public function setAccessMode(string $accessMode);

    /**
     * Check file access.
     *
     * @param bool $read
     *            Force read checking.
     * @param bool $write
     *            Force write checking.
     * @throws FileNotFoundException The file doesn't exist.
     * @throws IOException The file cannot be accessed in read mode (code = 1).
     * @throws IOException The file cannot be accessed in read mode (code = 2).
     * @throws IOException Unknown access mode (code = 3).
     */
    public function check(bool $read = false, bool $write = false);

    /**
     * Is the file existing?
     *
     * @return bool
     */
    public function isExisting();

    /**
     * Is the file readable?
     *
     * @return bool
     */
    public function isReadable();

    /**
     * Is the file writable?
     *
     * @return bool
     */
    public function isWritable();

    /**
     * Process file line by line.
     *
     * @param callable $callback
     *            The callback.
     *
     */
    public function processLines($callback);

    /**
     * Append content in file.
     *
     * @param string $content
     *            Amended content.
     * @param int|null $position
     *            Amend position
     */
    public function amend(string $content, int $position = null);
}