using System.Windows.Forms;
using SepehrFlightApiSampleClient.Availability.WinForms.SearchByRouteAndDate.ViewModels;

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

        public void SetFlightClass(FlightClass flightClassViewModel)
        {
            if (flightClassViewModel.CharterFare != null)
            {
                //adult
                var adultUserControl = new AgeTypeUserControl_Charter();
                adultUserControl.Location = new System.Drawing.Point(6, 6);
                adultUserControl.Dock = DockStyle.Fill;

                adultUserControl.SetData(
                    flightClassViewModel.CharterFare.Adult_Fare,
                    flightClassViewModel.AdultFreeBaggage);

                tbgAdult.Controls.Clear();
                tbgAdult.Controls.Add(adultUserControl);

                //child
                var childUserControl = new AgeTypeUserControl_Charter();
                childUserControl.Location = new System.Drawing.Point(6, 6);
                childUserControl.Dock = DockStyle.Fill;

                childUserControl.SetData(
                    flightClassViewModel.CharterFare.Child_Fare,
                    flightClassViewModel.ChildFreeBaggage);

                tbgChild.Controls.Clear();
                tbgChild.Controls.Add(childUserControl);

                //infant
                var infantUserControl = new AgeTypeUserControl_Charter();
                infantUserControl.Location = new System.Drawing.Point(6, 6);
                infantUserControl.Dock = DockStyle.Fill;

                infantUserControl.SetData(
                    flightClassViewModel.CharterFare.Infant_Fare,
                    flightClassViewModel.InfantFreeBaggage);

                tbgInfant.Controls.Clear();
                tbgInfant.Controls.Add(infantUserControl);
            }
            else
            {
                //adult
                var adultUserControl = new AgeTypeUserControl_Webservice();
                adultUserControl.Location = new System.Drawing.Point(6, 6);
                adultUserControl.Dock = DockStyle.Fill;

                adultUserControl.SetData(
                    flightClassViewModel.WebserviceFare.OnewayFare.Adult_Fare,
                    flightClassViewModel.WebserviceFare.RoundtripFare_FromOrigin?.Adult_Fare,
                    flightClassViewModel.WebserviceFare.RoundtripFare_FromDestination?.Adult_Fare,
                    flightClassViewModel.AdultFreeBaggage);

                tbgAdult.Controls.Clear();
                tbgAdult.Controls.Add(adultUserControl);

                //child
                var childUserControl = new AgeTypeUserControl_Webservice();
                childUserControl.Location = new System.Drawing.Point(6, 6);
                childUserControl.Dock = DockStyle.Fill;

                childUserControl.SetData(
                    flightClassViewModel.WebserviceFare.OnewayFare.Child_Fare,
                    flightClassViewModel.WebserviceFare.RoundtripFare_FromOrigin?.Child_Fare,
                    flightClassViewModel.WebserviceFare.RoundtripFare_FromDestination?.Child_Fare,
                    flightClassViewModel.ChildFreeBaggage);

                tbgChild.Controls.Clear();
                tbgChild.Controls.Add(childUserControl);

                //infant
                var infantUserControl = new AgeTypeUserControl_Webservice();
                infantUserControl.Location = new System.Drawing.Point(6, 6);
                infantUserControl.Dock = DockStyle.Fill;

                infantUserControl.SetData(
                    flightClassViewModel.WebserviceFare.OnewayFare.Infant_Fare,
                    flightClassViewModel.WebserviceFare.RoundtripFare_FromOrigin?.Infant_Fare,
                    flightClassViewModel.WebserviceFare.RoundtripFare_FromDestination?.Infant_Fare,
                    flightClassViewModel.InfantFreeBaggage);

                tbgInfant.Controls.Clear();
                tbgInfant.Controls.Add(infantUserControl);
            }
            

            txtCancelationPolicy.Text = flightClassViewModel.CancelationPolicy;
        }
    }
}
