using System;
using System.Windows.Forms;
using SepehrFlightApiSampleClient.BuiltinTypeExtensions;
using SepehrFlightApiSampleClient.Generic.WebApi;

namespace SepehrFlightApiSampleClient.Generic.WinForms
{
    public partial class AccountingReportForm : Form
    {
        private readonly MainForm _mainForm;

        public AccountingReportForm(MainForm mainForm)
        {
            _mainForm = mainForm;
            InitializeComponent();
        }

        private void btnCurrentBalance_Click(object sender, EventArgs e)
        {
            var request = new Sepehr.ApiGateway.Partners.Contracts.Generic.AccountingReport.V2.RequestModel.Request
            {
                Username = _mainForm.txtUsername.Text,
                Password = _mainForm.txtPassword.Text,
                FromDate = dtpFromDate.Value.ToString("yyyy-MM-dd"),
                ToDate = dtpToDate.Value.ToString("yyyy-MM-dd"),
                LastRecordId = null,
            };

            var response = AccountingReportApi.Post(_mainForm.txtUrl.Text, request);

            txtResponse.Text = response.SerializeToJsonWithFormatIndented();
            txtResponse.Visible = true;

            MessageBox.Show("Done :)");
        }
    }
}
