using System.Collections.Generic;
using System.Windows.Forms;
using SepehrFlightApiSampleClient.BuiltinTypeExtensions;
using SepehrFlightApiSampleClient.BulkAvailability.WinForms.DateRange.ViewModels;

// ReSharper disable InconsistentNaming

namespace SepehrFlightApiSampleClient.BulkAvailability.WinForms.DateRange
{
    public partial class AgeTypeUserControl : UserControl
    {
        public AgeTypeUserControl()
        {
            InitializeComponent();
        }

        public void SetData(
            Fare onewayFare,
            Fare roundtripFare_FromOrigin,
            Fare roundtripFare_FromDestination,
            FreeBaggage freeBaggage)
        {
            gridOneway.DataSource = GetItemList(onewayFare);
            gridBaggage.DataSource = GetItemList(freeBaggage);

            if (roundtripFare_FromOrigin != null)
            {
                gridRoundtripSameOrigin.DataSource = GetItemList(roundtripFare_FromOrigin);
            }
            else
            {
                tabControlPart1.TabPages.Remove(tbgRoundtripSameOrigin);
            }

            if (roundtripFare_FromDestination != null)
            {
                gridRoundtripOppositeOrigin.DataSource = GetItemList(roundtripFare_FromDestination);
            }
            else
            {
                tabControlPart1.TabPages.Remove(tbgRoundtripOppositeOrigin);
            }
        }

        private static List<Item> GetItemList(FreeBaggage freeBaggage)
        {
            return new List<Item>()
            {
                new Item
                {
                    Desc = nameof(FreeBaggage.CheckedBaggageQuantity),
                    Amount = freeBaggage.CheckedBaggageQuantity.ToString("N0"),
                },
                new Item
                {
                    Desc = nameof(FreeBaggage.CheckedBaggageTotalWeight),
                    Amount = freeBaggage.CheckedBaggageTotalWeight.ToString("N0"),
                },
                new Item
                {
                    Desc = nameof(FreeBaggage.HandBaggageQuantity),
                    Amount = freeBaggage.HandBaggageQuantity.ToString("N0"),
                },
                new Item
                {
                    Desc = nameof(FreeBaggage.HandBaggageTotalWeight),
                    Amount = freeBaggage.HandBaggageTotalWeight.ToString("N0"),
                }
            };
        }

        private static List<Item> GetItemList(Fare fare)
        {
            return new List<Item>()
            {
                new Item
                {
                    Desc = nameof(Fare.BaseFare),
                    Amount = fare.BaseFare.FormattedNumber(),
                },
                new Item
                {
                    Desc = nameof(Fare.TotalTax),
                    Amount = fare.TotalTax.FormattedNumber(),
                },
                new Item
                {
                    Desc = nameof(Fare.TotalFare),
                    Amount = fare.TotalFare.FormattedNumber(),
                },
                new Item
                {
                    Desc = nameof(Fare.Commission),
                    Amount = fare.Commission.FormattedNumber(),
                },
                new Item
                {
                    Desc = nameof(Fare.Markup),
                    Amount = fare.Markup.FormattedNumber(),
                },
                new Item
                {
                    Desc = nameof(Fare.Payable),
                    Amount = fare.Payable.FormattedNumber(),
                },
            };
        }

        private class Item
        {
            public string Desc { get; set; }

            public string Amount { get; set; }
        }
    }
}
