using FluidSim.Interfaces;

namespace FluidSim.Components
{
    public class Atmosphere : IComponent
    {
        public float Pressure { get; set; } = 101325f;
        public float Temperature { get; set; } = 300f;
        public float GasConstant { get; set; } = 287f;
        public float Gamma => 1.4f;

        public float Density => Pressure / (GasConstant * Temperature);
        public float SpecificEnthalpy => Gamma / (Gamma - 1f) * Pressure / Density;

        public Port Port { get; }

        public Atmosphere()
        {
            Port = new Port { Owner = this };
            UpdatePort();
        }

        public IReadOnlyList<Port> Ports => new[] { Port };

        public void UpdateState(float dt)
        {
            UpdatePort();
        }

        private void UpdatePort()
        {
            Port.Pressure = Pressure;
            Port.Density = Density;
            Port.Temperature = Temperature;
            Port.SpecificEnthalpy = SpecificEnthalpy;
            Port.AirFraction = 1f;
        }
    }
}