using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MachUtilPlanner
{
    public delegate double FailureRateFunc(double t);

    public class FailureRate
    {
        public static double Weibull(double t, double m = 1, double eta = 1, double gamma = 0)
        {
            return m / eta * Math.Pow((t - gamma) / eta, m - 1);
        }
    }

    public class ThreePhaseFailureRate : FailureRate
    {
        public double T1, m1, eta1, gamma1, T2, m2, eta2, gamma2, T3, m3, eta3, gamma3;

        public ThreePhaseFailureRate(double T1, double m1, double eta1, double gamma1, double T2, double m2, double eta2, double gamma2, double T3, double m3, double eta3, double gamma3)
        {
            this.T1 = T1;
            this.m1 = m1;
            this.eta1 = eta1;
            this.gamma1 = gamma1;
            this.T2 = T2;
            this.m2 = m2;
            this.eta2 = eta2;
            this.gamma2 = gamma2;
            this.T3 = T3;
            this.m3 = m3;
            this.eta3 = eta3;
            this.gamma3 = gamma3;
        }

        public double FailureRateFunc (double t)
        {
            if (t < T1)
                return Weibull(t, m1, eta1, gamma1);
            else if (t <= T2)
                return Weibull(t, m2, eta2, gamma2);
            else
                return Weibull(t, m3, eta3, gamma3);
        }

        static ThreePhaseFailureRate tpfr1;
        public static ThreePhaseFailureRate EnginFailureRate1
        {
            get
            {
                if (tpfr1 == null)
                    tpfr1 = new ThreePhaseFailureRate(430, 0.55, 23.8, -1, 785, 1.93, 301, 138, 1200, 3.06, 387, 289);
                return tpfr1;
            }
        }
    }
}
