using Back.Data.Models;
using Back.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Shared.DTOs;
using Shared.DTOs.Serch;

namespace Back.Controllers
{
    [Route("api/[controller]")]
    [Authorize]
    [ApiController]
    public class stuffController : ControllerBase
    {
        private readonly Servstuff _Servstuff;
        public stuffController(Servstuff Servstuff)
        {
            _Servstuff = Servstuff;
        }
        [HttpPost("Getstuff")]
        public async Task<ActionResult<PagingDto<stuffDto>>> Getstuff(GridDataProviderRequestDto value)
        {
            return Ok(await _Servstuff.Getstuff(value));
        }
        //[HttpPost("InitalInTb")]
        //public async Task<ActionResult> InitalInTb()
        //{
        //    int countererror = 0;
        //    List<stuff> stuffDtos = new List<stuff>();
        //    //------
        //    using (StreamReader sr = new StreamReader("C://AllserviceStuff.CSV"))
        //    {
        //        string line = "";
        //        while ((line = sr.ReadLine()) != null)
        //        {
        //            string[] cells = line.Split(new char[] { '\r', '\n' }, StringSplitOptions.None);
        //            if (cells.Length > 0)
        //            {
        //                var item = cells[0].Split(',');
        //                if (item[0] == "ID") continue;
        //                try
        //                {
        //                    stuffDtos.Add(new stuff
        //                    {
        //                        CID = item[0],
        //                        sType = item[1],
        //                        sDate = item[2],
        //                        RunDate = item[3],
        //                        ExpirationDate = item[4],
        //                        SpecialOrGeneral = item[5],
        //                        TaxableOrFree = item[6],
        //                        Vat = item[7],
        //                        VatCustomPurposes = item[8],
        //                        DescriptionOfID = item[9]
        //                    });
        //                }
        //                catch (Exception)
        //                {
        //                    countererror++;

        //                }

        //            }
        //        }
        //    }
         
        //    return Ok(await _Servstuff.AddRange(stuffDtos));
        //}
    }
}
