using Ato.CD.Inbound.Shared;
using Ato.EN.IntegrationServices.CodeGenerationCTR;
using Ato.EN.IntegrationServices.CodeGenerationRPTTAXPOS;
using DataContracts;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using VaTS;


namespace Ato.CD.Inbound.CTR202602
{
    public class CrossFormValidatorRPTTAXPOS : ICrossFormValidator
    {
        private CTR2026Validator validator = new CTR2026Validator();
        private CTR2026 ParentDocument { get; }
        private RPTTAXPOS2019 ChildDocument { get; }
        public List<ProcessMessageDocument> Response { get; private set; }

        public CrossFormValidatorRPTTAXPOS(CTR2026 report, BusinessDocument childDocument)
        {
            ParentDocument = report;
            ChildDocument = (RPTTAXPOS2019)childDocument.ConsumedReport;
            Response = new List<ProcessMessageDocument>();
        }

        public List<ProcessMessageDocument> ValidateCrossFormRules()
        {
            VRATOCTR500401();
            VRATOCTR500402();
            return Response;
        }

        #region VR.ATO.CTR.500401

        /*  VR.ATO.CTR.500401
            The start date in reportable tax position schedule must be the same as the start date provided in its parent form

            Legacy Rule Format:
                    IF COUNT(SCHEDULE = "RPTTAXPOS") = 1 AND RP:period.startDate <> ^RPTTAXPOS:RP:period.startDate
                       RETURN VALIDATION MESSAGE
                    ENDIF

            Data Elements:
            CTR Start Date = xbrli:xbrl/xbrli:context[0]/xbrli:period/xbrli:startDate
            RPTTAXPOS Start Date= xbrli:xbrl/xbrli:context/xbrli:period/xbrli:startDate
        */
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public virtual void VRATOCTR500401()
        {
            ProcessMessageDocument processMessage;
            bool assertion = !ParentDocument.RPStartDate.Equals(ChildDocument.RPStartDate);

            if (assertion)
            {
                processMessage = new ProcessMessageDocument
                {
                    Code = "CMN.ATO.CTR.500401",
                    Severity = ProcessMessageSeverity.Error,
                    Description = @"The start date in reportable tax position schedule must be the same as the start date provided in its parent form",
                    Location = "/xbrli:xbrl/xbrli:context" + validator.OccurrenceIndex(ParentDocument.RPOccurrenceIndex) + "/xbrli:period/xbrli:startDate",
                    Parameters = new ProcessMessageParameters
                    {
                        new ProcessMessageParameter { Name = "RuleIdentifier", Value = "VR.ATO.CTR.500401" },
                        new ProcessMessageParameter { Name = "CTR Start Date", Value = CTR2026Validator.GetValueOrEmptyDate(ParentDocument.RPStartDate) },
                        new ProcessMessageParameter { Name = "RPTTAXPOS Start Date", Value = CTR2026Validator.GetValueOrEmptyDate(ChildDocument.RPStartDate) }
                    },
                    DocumentSequence = "parent_doc"
                };

                Response.Add(processMessage);
            }
        }

        #endregion // VR.ATO.CTR.500401

        #region VR.ATO.CTR.500402

        /*  VR.ATO.CTR.500402
            The end date in reportable tax position schedule must be the same as the end date provided in its parent form

            Legacy Rule Format:
                    IF COUNT(SCHEDULE = "RPTTAXPOS") = 1 AND RP:period.endDate <> ^RPTTAXPOS:RP:period.endDate
                       RETURN VALIDATION MESSAGE
                    ENDIF

            Data Elements:
            CTR End Date = xbrli:xbrl/xbrli:context[0]/xbrli:period/xbrli:endDate
            RPTTAXPOS End Date= xbrli:xbrl/xbrli:context/xbrli:period/xbrli:endDate
        */
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public virtual void VRATOCTR500402()
        {
            ProcessMessageDocument processMessage;
            bool assertion = !ParentDocument.RPEndDate.Equals(ChildDocument.RPEndDate);

            if (assertion)
            {
                processMessage = new ProcessMessageDocument
                {
                    Code = "CMN.ATO.CTR.500402",
                    Severity = ProcessMessageSeverity.Error,
                    Description = @"The end date in reportable tax position schedule must be the same as the end date provided in its parent form",
                    Location = "/xbrli:xbrl/xbrli:context" + validator.OccurrenceIndex(ParentDocument.RPOccurrenceIndex) + "/xbrli:period/xbrli:endDate",
                    Parameters = new ProcessMessageParameters
                    {
                        new ProcessMessageParameter { Name = "RuleIdentifier", Value = "VR.ATO.CTR.500402" },
                        new ProcessMessageParameter { Name = "CTR End Date", Value = CTR2026Validator.GetValueOrEmptyDate(ParentDocument.RPEndDate) },
                        new ProcessMessageParameter { Name = "RPTTAXPOS End Date", Value = CTR2026Validator.GetValueOrEmptyDate(ChildDocument.RPEndDate) }
                    },
                    DocumentSequence = "parent_doc"
                };

                Response.Add(processMessage);
            }
        }
        #endregion // VR.ATO.CTR.500402

 
    }
}
