using System;
using System.Windows.Forms;
using SepehrFlightApiSampleClient.Availability.WebApi.ActiveRoutes;
using RequestModel = Sepehr.ApiGateway.Partners.Contracts.Flight.Availability.V11.ActiveRoutes.Charter.RequestModel;

namespace SepehrFlightApiSampleClient.Availability.WinForms.ActiveRoutes
{
    public partial class ActiveRoutesForm : Form
    {
        private readonly MainForm _mainForm;

        public ActiveRoutesForm(MainForm mainForm)
        {
            _mainForm = mainForm;
            InitializeComponent();

            gridCharterActiveRoutes.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            gridWebserviceActiveRoutes.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
        }

        private void btnGetActiveRoutes_Click(object sender, EventArgs e)
        {
            var request = new RequestModel.Request
            {
                UserName = _mainForm.txtUsername.Text,
                Password = _mainForm.txtPassword.Text,
            };

            var charterResponse = CharterActiveRoutesApi.Post(_mainForm.txtUrl.Text, request);
            gridCharterActiveRoutes.DataSource = charterResponse.ActiveRouteList;

            var webserviceResponse = WebserviceActiveRoutesApi.Post(_mainForm.txtUrl.Text, request);
            gridWebserviceActiveRoutes.DataSource = webserviceResponse.ActiveRouteList;
        }
    }
}
