using Elwig.Documents;
using Elwig.Helpers;
using Elwig.Models.Dtos;

namespace Tests.UnitTests.DocumentTests {
    [TestFixture]
    public class DeliveryConfirmationTest {

        [Test]
        public async Task Test_01_SimpleDeliveryConfirmation() {
            using var ctx = new AppDbContext();
            var m = await ctx.Members.FindAsync(101);
            var data = await DeliveryConfirmationDeliveryData.ForMember(ctx.DeliveryParts, 2020, m!);
            using var doc = new DeliveryConfirmation(ctx, 2020, m!, data);
            var text = await Utils.GeneratePdfText(doc);
            Assert.Multiple(() => {
                Assert.That(text, Contains.Substring("""
                    MUSTERMANN Max
                    Winzerstraße 1
                    2223 Hohenruppersdorf
                    """));
                Assert.That(text, Contains.Substring("0123463"));  // Betriebsnummer
                Assert.That(text, Contains.Substring("pauschaliert"));
                Assert.That(text, Contains.Substring($"Wolkersdorf, am {Elwig.Helpers.Utils.Today:dd.MM.yyyy}"));
                Assert.That(text, Contains.Substring("Anlieferungsbestätigung 2020"));
                Assert.That(text, Contains.Substring("""
                    20201001X001 1 Grüner Veltliner Qualitätswein 73 15,0 ungeb.: 3 219 3 219 ☑
                    20201001X003 2 Grüner Veltliner Kabinett Wein 87 17,6 ungeb.: 3 129 3 129 ☑
                    20201001X003 3 Grüner Veltliner Wein 79 16,1 ungeb.: 1 280 1 280 ☑
                    20201001X003 1 Grüner Veltliner Wein 75 15,4 ungeb.: 2 561 2 561 ☑
                    20201001X005 2 Welschriesling Kabinett 84 17,1 ungeb.: 2 190 2 190 ☑
                    20201001X005 1 Welschriesling Kabinett 84 17,0 ungeb.: 3 192 3 192 ☑
                    """));
                Assert.That(text, Contains.Substring("Gesamt: 15 571"));
                Assert.That(text, Contains.Substring("""
                    Sortenaufteilung [kg] ohne Attr./Bewirt. Kabinett Gesamt
                    Grüner Veltliner 7 060 3 129 10 189
                    Welschriesling 5 382 - 5 382
                    12 442 3 129 15 571
                    """));
            });
        }
    }
}
