using Hcs.Client;
using Hcs.Client.Api.Payload.Bills;
using Hcs.Client.Api.Registry;
using Hcs.Client.Api.Type;
using System;
using System.Linq;

namespace Hcs.TestApp.Scenario
{
    internal class BillsScenario(UniClient client)
    {
        private readonly UniClient client = client;

        internal void ExportPaymentDocumentDataByPaymentDocumentID()
        {
            var result = client.Bills.ExportPaymentDocumentDataByPaymentDocumentIDAsync("00АА095186-02-5081").Result;
            Console.WriteLine("Scenario execution " + (result != null && result.Count() > 0 ? "succeeded" : "failed"));
        }

        internal void ExportPaymentDocumentDataByAccountNumber()
        {
            var result = client.Bills.ExportPaymentDocumentDataByAccountNumberAsync(2025, 8, "c48e5025-f77a-494f-8aab-f773da623a25", "458938932489324").Result;
            Console.WriteLine("Scenario execution " + (result != null && result.Count() > 0 ? "succeeded" : "failed"));
        }

        internal void ExportPaymentDocumentDataByPaymentDocumentNumber()
        {
            var result = client.Bills.ExportPaymentDocumentDataByPaymentDocumentNumberAsync(2025, 8, "c48e5025-f77a-494f-8aab-f773da623a25", "23900701600162023").Result;
            Console.WriteLine("Scenario execution " + (result != null && result.Count() > 0 ? "succeeded" : "failed"));
        }

        internal void ImportPaymentDocumentData()
        {
            var paymentInformation = new ImportPaymentDocumentDataPayload.PaymentInformation()
            {
                bankBIK = "049805609",
                operatingAccountNumber = "40602810276000100228"
            };
            var payload = new ImportPaymentDocumentDataPayload()
            {
                confirmAmountsCorrect = true,
                month = 8,
                year = 2025,
                paymentInformation = [paymentInformation],
                paymentDocument = [new ImportPaymentDocumentDataPayload.PaymentDocument()
                {
                    paymentInformation = paymentInformation,
                    accountGuid = "019917a8-6eb6-74cc-99b7-58350127ac50",
                    paymentDocumentNumber = "23900701600162023",
                    chargeInfo =
                    [
                        new ImportPaymentDocumentDataPayload.MunicipalService()
                        {
                            moneyRecalculation = 0M,
                            moneyDiscount = 0M,
                            houseOverallNeedsNorm = 0M,
                            individualConsumptionNorm = 0.472M,
                            individualConsumptionCurrentValue = 0M,
                            houseOverallNeedsCurrentValue = 0M,
                            houseTotalIndividualConsumption = 19.678M,
                            houseTotalHouseOverallNeeds = 0M,
                            individualConsumptionVolumeDeterminingMethod = MunicipalServiceVolumeDeterminingMethod.Norm,
                            individualConsumptionVolumeValue = 1.006M,
                            municipalServiceIndividualConsumptionPayable = 1862.93M,
                            municipalServiceCommunalConsumptionPayable = 0M,
                            amountOfPaymentMunicipalServiceIndividualConsumption = 1862.93M,
                            amountOfPaymentMunicipalServiceCommunalConsumption = 0M,
                            serviceType = Registry51.Element6_1,
                            rate = 1851.82M,
                            totalPayable = 1862.93M,
                            accountingPeriodTotal = 1862.93M
                        }
                    ],
                    exposeNotWithdraw = true,
                    debtPreviousPeriods = 3271.16M,
                    advanceBllingPeriod = 0M,
                    totalPayableByPDWithDebtAndAdvance = 3043.95M,
                    totalPayableByPD = 3442.24M,
                    paidCash = 3669.45M,
                    dateOfLastReceivedPayment = new DateTime(2025, 8, 30)
                }]
            };

            var result = client.Bills.ImportPaymentDocumentDataAsync(payload).Result;
            Console.WriteLine("Scenario execution " + (result ? "succeeded" : "failed"));
        }
    }
}
