using System;
using System.Collections.Generic;
using DataContracts;
using System.Linq;

namespace Ato.EN.IntegrationServices.CodeGenerationRPTTAXPOS
{
    public partial class RPTTAXPOS2019Validator 
    {
        #region VR.ATO.RPTTAXPOS.000006

        /*  VR.ATO.RPTTAXPOS.000006
        RTP Category A & B Number must be unique and in incremental sequential order starting from '20xx-001' up to the supplied number of Category A & B reportable tax position.

        Legacy Rule Format:
        WHERE IN TUPLE(rpttaxpos.0001.lodge.req.xx.xx:ReportableTaxPositionCategoryAAndB)
        IF ANY OCCURRENCE OF [RPTTAXPOS4] <> INCREMENTAL SEQUENCE OF ANY OTHER OCCURRENCE OF [RPTTAXPOS4]
            RETURN VALIDATION MESSAGE
        ENDIF
                
        [RPTTAXPOS4] = RPTTAXPOS:RP:bafot.02.36:RegulatoryDisclosures.ReportableTaxPositionCategoryReferenceNumber.Identifier IN TUPLE(rpttaxpos.0001.lodge.req.02.00:ReportableTaxPositionCategoryAAndB)
   
        Data Elements:
        
        ^RPTTAXPOS4 = RP:ReportableTaxPositionCategoryAAndB:RegulatoryDisclosures.ReportableTaxPositionCategoryReferenceNumber.Identifier
        */

        protected void VRATORPTTAXPOS000006(List<ProcessMessageDocument> response, RPTTAXPOS2019 report)
        {
            IEnumerable<ProcessMessageDocument> processMessages = report.ReportableTaxPositionCategoryAAndBCollection?
                                                                 .Where(rptCategoryAAndB => rptCategoryAAndB.RPTTAXPOS4 != null
                                                                  && rptCategoryAAndB.RPTTAXPOS4.Length == 8
                                                                  && rptCategoryAAndB.RPTTAXPOS4.Substring(5, rptCategoryAAndB.RPTTAXPOS4.Length - 5).All(char.IsDigit)
                                                                  && int.Parse(rptCategoryAAndB.RPTTAXPOS4.Substring(5, rptCategoryAAndB.RPTTAXPOS4.Length - 5)) != rptCategoryAAndB.OccurrenceIndex)
                                                                 .Select(rptCategoryAAndB => new ProcessMessageDocument
                                                                 {
                                                                     Code = "CMN.ATO.RPTTAXPOS.000006",
                                                                     Severity = ProcessMessageSeverity.Error,
                                                                     Description = @"Last three digits of the RTP Category A & B Number is incorrect.",
                                                                     LongDescription = @"RTP Category A & B Number must have the last three digits in sequential order with an increment of one and starting from '001' up to the supplied number in 'How many Category A or B Reportable tax positions are you reporting?'.",
                                                                     Location = "/xbrli:xbrl/tns:ReportableTaxPositionCategoryAAndB" + OccurrenceIndex(rptCategoryAAndB.OccurrenceIndex) + "/tns:RegulatoryDisclosures.ReportableTaxPositionCategoryReferenceNumber.Identifier",
                                                                     Parameters = new ProcessMessageParameters
                                                                     {
                                                                        new ProcessMessageParameter { Name = "RuleIdentifier", Value = "VR.ATO.RPTTAXPOS.000006" },
                                                                        new ProcessMessageParameter { Name = "RPTTAXPOS4", Value = rptCategoryAAndB.RPTTAXPOS4 }
                                                                     }
                                                                 });

            if (processMessages?.Count() > 0)
            {
                response.AddRange(processMessages);
            }
        }

        #endregion // VR.ATO.RPTTAXPOS.000006

        #region VR.ATO.RPTTAXPOS.000015

        /*  VR.ATO.RPTTAXPOS.000015
        RTP Category C Number must be unique and in incremental sequential order starting from '20xx-001' up to the supplied number of Category C reportable tax position.

        Legacy Rule Format:
        WHERE IN TUPLE(rpttaxpos.0001.lodge.req.xx.xx:ReportableTaxPositionCategoryC)
        IF ANY OCCURRENCE OF [RPTTAXPOS11] <> INCREMENTAL SEQUENCE OF ANY OTHER OCCURRENCE OF [RPTTAXPOS11]
            RETURN VALIDATION MESSAGE
        ENDIF
            
        [RPTTAXPOS11] = RPTTAXPOS:RP:bafot.02.36:RegulatoryDisclosures.ReportableTaxPositionCategoryReferenceNumber.Identifier IN TUPLE(rpttaxpos.0001.lodge.req.02.00:ReportableTaxPositionCategoryC)

        Data Elements:
    
        ^RPTTAXPOS11 = RP:ReportableTaxPositionCategoryC:RegulatoryDisclosures.ReportableTaxPositionCategoryReferenceNumber.Identifier
        */
        protected void VRATORPTTAXPOS000015(List<ProcessMessageDocument> response, RPTTAXPOS2019 report)
        {
            IEnumerable<ProcessMessageDocument> processMessages = report.ReportableTaxPositionCategoryCCollection?
                                                                  .Where(rptCategoryC => rptCategoryC.RPTTAXPOS11 != null
                                                                   && rptCategoryC.RPTTAXPOS11.Length == 8
                                                                   && rptCategoryC.RPTTAXPOS11.Substring(5, rptCategoryC.RPTTAXPOS11.Length - 5).All(char.IsDigit)
                                                                   && int.Parse(rptCategoryC.RPTTAXPOS11.Substring(5, rptCategoryC.RPTTAXPOS11.Length - 5)) != rptCategoryC.OccurrenceIndex)
                                                                   .Select(rptCategoryC => new ProcessMessageDocument
                                                                   {
                                                                       Code = "CMN.ATO.RPTTAXPOS.000015",
                                                                       Severity = ProcessMessageSeverity.Error,
                                                                       Description = @"Last three digits of the RTP Category C Number is incorrect.",
                                                                       LongDescription = @"RTP Category C Number must have the last three digits in sequential order with an increment of one and starting from '001' up to the supplied number in 'How many Category C Reportable tax positions are you reporting?'.",
                                                                       Location = "/xbrli:xbrl/tns:ReportableTaxPositionCategoryC" + OccurrenceIndex(rptCategoryC.OccurrenceIndex) + "/tns:RegulatoryDisclosures.ReportableTaxPositionCategoryReferenceNumber.Identifier",
                                                                       Parameters = new ProcessMessageParameters
                                                                       {
                                                                            new ProcessMessageParameter { Name = "RuleIdentifier", Value = "VR.ATO.RPTTAXPOS.000015" },
                                                                            new ProcessMessageParameter { Name = "RPTTAXPOS11", Value = rptCategoryC.RPTTAXPOS11 }
                                                                       }
                                                                   });

            if (processMessages?.Count() > 0)
            {
                response.AddRange(processMessages);
            }
        }

        #endregion // VR.ATO.RPTTAXPOS.000015
    }
}
