package fr.umlv.tpnotesept;

import java.io.Closeable;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.file.Path;

/**
 * A logger is an object that will write log records or using a {@link Writer}
 * or using a {@link Path}.
 * The method #close() closes the connection to the writer and closed all
 * logs created form this Logger that are not already closed.
 * 
 * @see #Logger(Writer)
 * @see #Logger(Path, Charset)
 */
public class Logger implements Closeable {
  /**
   * An object that stores log records inserted using {@link #log(String)}
   * until its method {@link #close()} is called.
   */
  public interface Log extends Closeable {
    /**
     * Return if the current log is closed or not.
     * This method can be called by any thread and is thread safe.
     * @return true if the current log is closed.
     */
    public boolean isClosed();

    /**
     * Log a text in a buffer, all the message logged will be dumped
     * when the current log will be closed.
     * This method must be called only by the thread that has created the current Log object.
     * @param text a text to log, an '\n' will be added automatically at the end of the text.
     * @throws IllegalStateException if this method is not called by the thread that has
     *   created this object or if the current log is {@link #isClosed() closed}.
     */
    public void log(String text);
  }

  /**
   * Create a Logger with a writer that will be used to write the log record logged by the different logs
   * created from this Logger.
   * @param writer a writer
   * 
   * @see #createLog()
   */
  public Logger(Writer writer) {
    //TODO
  }

  /**
   * Create a Logger with a path corresponding to a file on the file system and a charset.
   * @param path a path
   * @param charset a charset
   * @throws IOException if the path is not a file or can not be opened to write in it.
   */
  public Logger(Path path, Charset charset) throws IOException {
    //TODO
  }

  /**
   * Creates a log for the current thread.
   * @return a new log for the current thread.
   * @throws IllegalStateException if a log already exist for the current thread.
   * 
   * @see #getLog()
   */
  public Log createLog() {
    //TODO
  }

  /**
   * Returns the log object linked to the current thread.
   * @return the log object linked to the current thread.
   * @throws IllegalStateException if no log exist for the current thread.
   * 
   * @see #createLog()
   */
  public Log getLog() {
    //TODO
  }
}
