/*
 * Author:          Patrick-Christopher Mattulat
 * Co-Author:       Claude Sonnet 4.6 (LLM)
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2020-08-17
 * Changed:         2026-06-23
 *
 * */

#include <fstream>
#include <ls-std/io/FileWriter.hpp>
#include <ls-std/io/evaluator/FileExistenceEvaluator.hpp>

using ls::standard::core::Class;
using ls::standard::core::type::byte_field;
using ls::standard::io::File;
using ls::standard::io::FileExistenceEvaluator;
using ls::standard::io::FileWriter;
using ::std::ofstream;

FileWriter::FileWriter(const File &_file) : Class("FileWriter"), file(_file)
{
  FileExistenceEvaluator{_file.getAbsoluteFilePath()}.evaluate();
}

FileWriter::~FileWriter() noexcept = default;

void FileWriter::reset(const File &_file)
{
  FileExistenceEvaluator{_file.getAbsoluteFilePath()}.evaluate();
  this->file = _file;
}

bool FileWriter::write(const byte_field &_data)
{
  ofstream outputStream{};
  outputStream.open(this->file.getAbsoluteFilePath());
  outputStream << _data;

  return !outputStream.fail();
}
