using Newtonsoft.Json;
using Ropin.Inspection.Model.Entities;
using Ropin.Inspection.Model;
using Ropin.Inspection.Model.ViewModel.DEV;
using Ropin.Inspection.Service.DEV.Interface;
using Ropin.Inspection.Service.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using LinqKit;
using Ropin.Inspection.Common;
using AutoMapper;
using Ropin.Inspection.Common.Accessor.Interface;
using Ropin.Inspection.Repository.DEV.Interface;
using Ropin.Inspection.Repository;
using Ropin.Inspection.Model.ViewModel;

namespace Ropin.Inspection.Service.DEV
{
    public class DevDevOpeAccountConfigService : IDevDevOpeAccountConfigService
    {
        private readonly Idev_DevOpeAccountConfigRepository _repository;
        private readonly IMapper _mapper;
        private readonly IClaimsAccessor _claims;
        private readonly InspectionDbContext _sqlDBContext;
        private readonly ITdevDevStoreRepository _devStoreRepository;

        public DevDevOpeAccountConfigService(IClaimsAccessor claims, InspectionDbContext sqlDBContext,  Idev_DevOpeAccountConfigRepository repository, IMapper mapper, ITdevDevStoreRepository devStoreRepository)
        {
            _repository = repository;
            _mapper = mapper;
            _claims = claims;
            _sqlDBContext = sqlDBContext;
            _devStoreRepository = devStoreRepository;
        }

        public async Task<DEV_DevOpeAccountConfigModel> GetDevOpeAccountConfigModelAsync(string devStoreCode)
        {
            var content =  _repository.GetAll().Where(t=>t.C_DevStoreCode== devStoreCode).OrderByDescending(t=>t.D_CreateOn).FirstOrDefault();
            if (content!=null)
            {
                return _mapper.Map<TDEV_DevOpeAccountConfig, DEV_DevOpeAccountConfigModel>(content);
            }
            else
            {
                return null;
            }
        }
        public Task CreateOneAsync(DEV_DevOpeAccountConfigModel viewModel)
        {
            throw new NotImplementedException();
        }

        public Task DeleteAsync(Guid id)
        {
            throw new NotImplementedException();
        }
        public async Task<DEV_DevOpeAccountConfigModel> GetEntityByID(string id)
        {
            var record = await _repository.GetByConditionAsync(t => t.C_ID==id);
            if (record != null)
            {
                var recordDto = _mapper.Map<TDEV_DevOpeAccountConfig, DEV_DevOpeAccountConfigModel>(record.FirstOrDefault());
                return recordDto;
            }
            return null;
        }
        public async Task<DEV_DevOpeAccountConfigModel> GetByIdAsync(Guid id)
        {
            throw new NotImplementedException();
        }

        public Task<bool> IsExistAsync(Guid id)
        {
            throw new NotImplementedException();
        }

        public Task<int> UpdateOneAsync(DEV_DevOpeAccountConfigModel viewModel, params string[] fields)
        {
            throw new NotImplementedException();
        }
    }
}