using System;
using System.Windows.Forms;
using SepehrHotelApiSampleClient.Booking.Book.WinForms.FakeData;
using BookRequestModel = Sepehr.ApiGateway.Partners.Contracts.Hotel.Booking.V2.Book.RequestModel;

namespace SepehrHotelApiSampleClient.Booking.Book.WinForms.PassengerUserControls
{
    public partial class ChildUserControl : UserControl
    {
        public ChildUserControl(byte childAge)
        {
            InitializeComponent();

            cmbDocType.SelectedIndex = 0;
            cmbTitle.SelectedIndex = 0;

            var birthDate = DateTime.Now.AddYears(-childAge);
            txtBirthdate_Year.Text = birthDate.ToString("yyyy");
            txtBirthdate_Month.Text = birthDate.ToString("MM");
            txtBirthdate_Day.Text = birthDate.ToString("dd");

            var passportExpiryDate = DateTime.Now.AddYears(2);
            txtPassportExpiryDate_Year.Text = passportExpiryDate.ToString("yyyy");
            txtPassportExpiryDate_Month.Text = passportExpiryDate.ToString("MM");
            txtPassportExpiryDate_Day.Text = passportExpiryDate.ToString("dd");

            cmbDocType.SelectedIndex = 1;
            txtDocNumber.Text = CodeMelliGenerator.Get();

            txtFirstname.Text = FirstNameGenerator.Get();
            txtLastname.Text = LastNameGenerator.Get();
        }

        public BookRequestModel.Guest GetGuestInfo()
        {
            return new BookRequestModel.Guest
            {
                Title = cmbTitle.SelectedItem.ToString(),
                FirstName = txtFirstname.Text,
                LastName = txtLastname.Text,
                BirthDate = $"{txtBirthdate_Year.Text}-{txtBirthdate_Month.Text}-{txtBirthdate_Day.Text}",
                IranianCartMelli = cmbDocType.SelectedItem.ToString() == "IranianCartMelli" ? new BookRequestModel.TravelDocument.IranianCartMelli
                {
                    CodeMelli = txtDocNumber.Text
                } : null,
                Passport = cmbDocType.SelectedItem.ToString() == "Passport"? new BookRequestModel.TravelDocument.Passport
                {
                    Number = txtDocNumber.Text,
                    ExpiryDate = $"{txtPassportExpiryDate_Year.Text}-{txtPassportExpiryDate_Month.Text}-{txtPassportExpiryDate_Day.Text}",
                    NationalityCountryCode = txtPassportNationalityCountryCode.Text,
                    PlaceOfIssueCountryCode = txtPassportPlaceOfIssueCountryCode.Text,
                } : null
            };
        }

        private void cmbDocType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (cmbDocType.SelectedIndex == 0)
            {
                pnlPassportInfo.Visible = true;
            }
            else
            {
                pnlPassportInfo.Visible = false;
            }
        }
    }
}
