/**
 * Copyright (C) 2016  Alexander Schmidt
 *
 * This file is part of Seamulator.
 *
 * Seamulator is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Seamulator is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Seamulator.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <chrono>
#include <complex>
#include <random>

#include <fftw3.h>

#include "seafwd.h"

#include "watersurfacefwd.h"

class Sea
{
 public:
  Sea(WaterSurfacePtr surface, double windSpeed, double magicConstant);
  ~Sea();
  Sea(const Sea&) = delete;
  Sea& operator=(const Sea&) = delete;
  void update();

 private:
  static const double GRAVITATIONAL_CONSTANT;

  WaterSurfacePtr m_surface;
  double m_windDirection[2];
  double m_windSpeed;
  double m_magicConstant;
  std::random_device m_randomDevice;
  std::mt19937 m_randomGenerator;
  std::normal_distribution<> m_normalDistribution;
  std::vector<std::complex<double>> m_fourierAmplitudes;
  fftw_complex *m_fftwIn, *m_fftwOut;
  fftw_plan m_fftwPlan;
  std::chrono::time_point<std::chrono::system_clock> m_startTime;

  double phillipsSpectrum(double k_x, double k_y) const;
  std::complex<double>& fourierAmplitudeAt(int n, int m);
  void generateFourierAmplitudes();
  double spatialFrequencyForIndex(int n) const;
  double getRuntime() const;
};
