using AsbCloudApp.Data.DetectedOperation;
using AsbCloudDb.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{
    public class DetectorConditioning : DetectorAbstract
    {
        protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end) =>
            CalcDeltaMinutes(telemetry, begin, end);

        protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation)
        {
            var currentPoint = telemetry[position];
            if (currentPoint.Pressure < 10)
                return false;

            if (currentPoint.RotorSpeed <= 8)
                return false;

            var delta = currentPoint.WellDepth - currentPoint.BitDepth;
            if (delta < 0.03d)
                return false;

            if (currentPoint.BitDepth < 150)
                return false;            

            return true;
        }

        protected override int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation)
        {
            var currentPoint = telemetry[position];

            if (currentPoint.Pressure < 10)
                return IdReasonOfEnd_PressureIsLo;
            if (currentPoint.RotorSpeed <=8)
                return IdReasonOfEnd_RotorSpeedIsHi;
            if ((currentPoint.WellDepth - currentPoint.BitDepth) < 0.03d)
                return IdReasonOfEnd_DeltaWellDepthAndBithDepthIsLo;
            if (currentPoint.BitDepth < 150)
                return IdReasonOfEnd_BithDepthIsLo;
            return IdReasonOfEnd_NotDetected;
        }

        protected override (int IdCategory, IDictionary<string, object> ExtraData) GetSpecificInformation(DetectableTelemetry[] telemetry, int begin, int end)
        {
            return (WellOperationCategory.IdConditioning, new Dictionary<string, object>());
        }
    }
}