using System;

namespace QuantEngine.Core.Domain
{
    public class PullbackTriggerResult
    {
        public string PullbackEntryVerdict { get; set; } = "ABOVE_PULLBACK_ZONE";
        public string PullbackState { get; set; } = "BLOCKED";
        public double PullbackEntryTriggerPrice { get; set; }
        public double PullbackUpperBand { get; set; }
    }

    public static class PullbackTriggerCalculator
    {
        public static PullbackTriggerResult ComputePullbackTrigger(double close, double ma20, double atr20)
        {
            double triggerPrice = KrxTickNormalizer.NormalizeTick(ma20 - 0.5 * atr20);
            double upperBand = ma20 * 1.03;
            string verdict;
            string state;

            if (close <= upperBand)
            {
                verdict = "PULLBACK_ZONE";
                state = "PASS";
            }
            else
            {
                verdict = "ABOVE_PULLBACK_ZONE";
                state = "BLOCKED";
            }

            return new PullbackTriggerResult
            {
                PullbackEntryVerdict = verdict,
                PullbackState = state,
                PullbackEntryTriggerPrice = triggerPrice,
                PullbackUpperBand = KrxTickNormalizer.NormalizeTick(upperBand)
            };
        }
    }
}
