using Newtonsoft.Json;
using System.Collections.Generic;
using LAPS_XMLQC_Service.App_Data;

namespace LAPS_XMLQC_Service.Controllers.WorkArea
{
    public interface IWorkAreaService
    {
        string GetServerPath(string id, bool createdir, string mode);
        object usrstagemove(object data);
        object getJobDetails(object data);
        object getFileTypeInput(string transactionid);
        object getFileTypeOutput(string transactionid);
    }
    public class WorkAreaService: IWorkAreaService
    {     
        private readonly CommonRepository oCommonRepository;
        public WorkAreaService(CommonRepository commonRepository)
        {
            oCommonRepository = commonRepository;
        }

        public string GetServerPath(string id, bool createdir, string mode)
        {
            string fileSaveLocation = oCommonRepository.GetServerPath(id, mode, createdir);
            return fileSaveLocation;
        }

        public object usrstagemove(object data)
        {
            var input = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnListWithoutMode("spusrstagemove", input);
        }

        public object getJobDetails(object data)
        {
            var input = JsonConvert.DeserializeObject<object>(data.ToString());
            var lotDetails = oCommonRepository.ExecuteSP_ReturnList("spgetlotandstagedetails", input.ToString(), "getlot");
            var stageDetails = oCommonRepository.ExecuteSP_ReturnList("spgetlotandstagedetails", input.ToString(), "getstage");
            var commentsDetails = oCommonRepository.ExecuteSP_ReturnList("spgetlotcommentslot", input.ToString(), "null");
            var json = new List<object>();
            json.Add(lotDetails);
            json.Add(stageDetails);
            json.Add(commentsDetails);
            return json;
        }

        public object getFileTypeInput(string transactionid)
        {
            var data = new { transactionid = transactionid };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList("splottransactionselect", jsonstr, "getfiletypeinput");
        }

        public object getFileTypeOutput(string transactionid)
        {
            var data = new { transactionid = transactionid };
            var jsonstr = JsonConvert.SerializeObject(data);
            return oCommonRepository.ExecuteSP_ReturnList("splottransactionselect", jsonstr, "getfiletypeoutput");
        }

    }

}
