﻿using NuClear.DataTest.Metamodel.Dsl;
using NuClear.ValidationRules.Storage.Identitites.EntityTypes;
using NuClear.ValidationRules.Storage.Model.Aggregates.AccountRules;
using NuClear.ValidationRules.Storage.Model.Messages;
using Facts = NuClear.ValidationRules.Storage.Model.Facts;
using Messages = NuClear.ValidationRules.Storage.Model.Messages;
using MessageTypeCode = NuClear.ValidationRules.Storage.Model.Messages.MessageTypeCode;

namespace NuClear.ValidationRules.Replication.StateInitialization.Tests
{
    public sealed partial class TestCaseMetadataSource
    {
        // ReSharper disable once UnusedMember.Local
        private static ArrangeMetadataElement BillsShouldBeCreated
            => ArrangeMetadataElement
                .Config
                .Name(nameof(BillsShouldBeCreated))
                .Fact(
                    // Платный заказ с созданными счетами
                    new Facts::Order { Id = 1, Start = MonthStart(1), PlanEnd = MonthStart(2), FactEnd = MonthStart(2) },
                    new Facts::OrderConsistency { Id = 1, BargainId = 1, IsFreeOfCharge = false},
                    new Facts::Bill { Id = 1, OrderId = 1, PayablePlan = 123 },
                    new Facts::OrderPosition { Id = 1, OrderId = 1 },
                    new Facts::ReleaseWithdrawal { OrderPositionId = 1, Amount = 123 },

                    // Бесплатный заказ с созданными счетами
                    new Facts::Order { Id = 2, Start = MonthStart(1), PlanEnd = MonthStart(2), FactEnd = MonthStart(2) },
                    new Facts::OrderConsistency { Id = 2, BargainId = 1, IsFreeOfCharge = true},
                    new Facts::Bill { Id = 2, OrderId = 2, PayablePlan = 123 },
                    new Facts::OrderPosition { Id = 2, OrderId = 2 },
                    new Facts::ReleaseWithdrawal { OrderPositionId = 2, Amount = 123 },

                    // Платный заказ без счетов
                    new Facts::Order { Id = 3, Start = MonthStart(1), PlanEnd = MonthStart(2), FactEnd = MonthStart(2) },
                    new Facts::OrderConsistency { Id = 3, BargainId = 1, IsFreeOfCharge = false},
                    new Facts::OrderPosition { Id = 3, OrderId = 3 },
                    new Facts::ReleaseWithdrawal { OrderPositionId = 3, Amount = 123 },

                    // Бесплатный заказ без счетов
                    new Facts::Order { Id = 4, Start = MonthStart(1), PlanEnd = MonthStart(2), FactEnd = MonthStart(2) },
                    new Facts::OrderConsistency { Id = 4, BargainId = 1, IsFreeOfCharge = true},
                    new Facts::OrderPosition { Id = 4, OrderId = 4 },
                    new Facts::ReleaseWithdrawal { OrderPositionId = 4, Amount = 123 },

                    // заказ без счетов и запланированных списаний
                    new Facts::Order { Id = 5, Start = MonthStart(1), PlanEnd = MonthStart(2), FactEnd = MonthStart(2) },
                    new Facts::OrderConsistency { Id = 5, BargainId = 1, IsFreeOfCharge = false},

                    new Facts::Bargain { Id = 1, AccountId = 1 },
                    new Facts::Account { Id = 1 })
                .Aggregate(
                    new Order { Id = 3, Start = MonthStart(1), End = MonthStart(2), AccountId = 1 },
                    new Order.MissingBills { OrderId = 3 },

                    new Order { Id = 1, Start = MonthStart(1), End = MonthStart(2), AccountId = 1 },
                    new Order { Id = 5, Start = MonthStart(1), End = MonthStart(2), AccountId = 1 })
                .Message(
                    new Messages::Version.ValidationResult
                        {
                            MessageParams = new MessageParams(new Reference(EntityType.Order, 3)).ToXDocument(),
                            MessageType = (int)MessageTypeCode.BillsShouldBeCreated,
                            PeriodStart = MonthStart(1),
                            PeriodEnd = MonthStart(2),
                            OrderId = 3,
                        });
    }
}
