﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataConnect.Infrastructure.Garmin.Utilities;
using DataConnect.Domain.LogModule;
using DataConnect.Infrastructure.Garmin.Base;
using DataConnect.Domain.SettingModule.Services;

namespace DataConnect.Infrastructure.Garmin.Client
{
    internal class GarminUploadClient : GarminClient
    {

        private const string URL_SEND_FILE = "https://connect.garmin.com/proxy/upload-service-1.1/json/upload/.fit";
        public GarminUploadClient(ISettingService settingService, ILogService logService) :
            base(settingService, logService)
        {
        }


        public async Task<ProcessResult> UploadFileAsync(string filePath)
        {
            if (string.IsNullOrEmpty(SessionTicket))
            {
                SessionTicket = await GetSessionTicketAsync();
            }

            var request = HttpUtilities.CreateRequest(URL_SEND_FILE, Cookies, "POST");
            request.CookieContainer = Cookies;
            return await request.WriteFormFileAsync(filePath);
        }

        protected override string ServiceLabel()
        {
            return "Garmin upload";
        }
    }
}
