using System.Collections.Generic;
using System.Windows.Forms;
using SepehrFlightApiSampleClient.Availability.WinForms.SearchByRouteAndDate.ViewModels;
using SepehrFlightApiSampleClient.BuiltinTypeExtensions;

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

        public void SetData(
            Fare fare,
            FreeBaggage freeBaggage)
        {
            gridFare.DataSource = GetItemList(fare);
            gridBaggage.DataSource = GetItemList(freeBaggage);
        }

        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.Tax),
                    Amount = fare.Tax.FormattedNumber(),
                },
                new Item
                {
                    Desc = nameof(Fare.TotalFare),
                    Amount = fare.TotalFare.FormattedNumber(),
                },
                new Item
                {
                    Desc = nameof(Fare.Commision),
                    Amount = fare.Commision.FormattedNumber(),
                },
                new Item
                {
                    Desc = nameof(Fare.Payable),
                    Amount = fare.Payable.FormattedNumber(),
                },
            };
        }

        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 class Item
        {
            public string Desc { get; set; }

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