using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Cors;
using System.Web.UI;
using RoketsanSaop.WebApi.Models;

namespace RoketsanSaop.WebApi.Controllers
{
    [EnableCors("*", "*", "*")]
    public class DataController : ApiController
    {
        private static readonly Logger _logger = LogManager.GetCurrentClassLogger();


        [HttpGet, ActionName("GetItemInfo")]
        public async Task<string> GetItemInfo(string tarBas = "", string tarBit = "")
        {
           
            try
            {

                RoketsanSoapService.ProjectServiceClient client = new RoketsanSoapService.ProjectServiceClient();
               // RoketsanSoapService.XXRKS_TT_INTEGRATION_WS_PortTypeClient client = new RoketsanSoapService.XXRKS_TT_INTEGRATION_WS_PortTypeClient();
                ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;

                client.ClientCredentials.UserName.UserName = "TT_INTEGRATION_SA";
                client.ClientCredentials.UserName.Password = "roketsan123";


                var adressbuilder = new EndpointAddressBuilder(client.Endpoint.Address);
                var serialize = new DataContractSerializer(typeof(ApiHeader));

                var csbheader = new ApiHeader
                {
                    Username = "TT_INTEGRATION_SA",
                    Password = "roketsan123",
                    UsernameToken = "UsernameToken-42F0F5FFF7C46C9B8A17376392679784",
                    Created = "2025-01-23T13:34:27.978Z",
                    Nonce = "ca13+ic+CPSfE4lYtkdtzw=="
                };

                adressbuilder.Headers.Add(System.ServiceModel.Channels.AddressHeader.CreateAddressHeader("Security", "", csbheader, serialize));
                client.Endpoint.Address = adressbuilder.ToEndpointAddress();


                // bunlar açılacak.
                //InputParameters _inputParameters = new InputParameters();
                //_inputParameters.P_START_DATE = Convert.ToDateTime(tarBas);
                //_inputParameters.P_END_DATE = Convert.ToDateTime(tarBit);

                //SOAHeader _SOAHeader = new SOAHeader();
                //_SOAHeader.Responsibility = "XXRKS_WS_NULL";
                //_SOAHeader.RespApplication = "XXRKS";
                //_SOAHeader.SecurityGroup = "STANDARD";
                //_SOAHeader.NLSLanguage = "AMERICAN";
                //_SOAHeader.Org_Id = "84";
              //  var response = await client.SEND_ITEM_INFOAsync(_SOAHeader, _inputParameters);


            }
            catch (Exception e)
            {
               
            }

            return "";
        }

    }
}
