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

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

        public void SetFare(
            Fare onewayFare,
            Fare roundtripFareSameOrigin,
            Fare roundtripFareOppositeOrigin)
        {
            gridOneway.DataSource = GetItemList(
                onewayFare);

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

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

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

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