using ASHermed.AdminInterface.Api.ContractModel;
using ASHermed.SinoInterface.Api.ContractModel.App;
using ASHermed.SinoInterface.Api.IRepository;
using ASHermed.SinoInterface.Repository.MySql;
using ASHermed.SinoInterface.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ASHermed.SinoInterface.Api.MySqlRepository.App
{
    public class FileRepository : BaseRepositoryToASHermed_SinoInterface<Sys_File>, IFileRepository
    {
        public List<Sys_File> GetFiles(List<int> Ids)
        {
            var sql = @" Select * From sys_file Where Id IN @Ids ";
            return Query<Sys_File>(sql, new { Ids = Ids }).ToList().DeEncrypt();
        }

        public List<Sys_File> GetFilesNoContent(List<int> Ids)
        {
            var sql = @" Select Id,FileUrl,FileType,IP,ContentType From sys_file Where Id IN @Ids ";
            return Query<Sys_File>(sql, new { Ids = Ids }).ToList().DeEncrypt();
        }

        public List<Sys_File> GetFilesForContent(List<int> Ids)
        {
            var sql = @" Select Id,FileUrl,Content,FileType,IP,ContentType From sys_file Where Id IN @Ids ";
            return Query<Sys_File>(sql, new { Ids = Ids }).ToList().DeEncrypt();
        }
        public Sys_File GetFilesContentForId(int id)
        {
            var sql = @" Select Id,FileUrl,Content,FileType,IP,ContentType From sys_file Where Id = @Id ";
            return Query<Sys_File>(sql, new { Id = id }).FirstOrDefault().DeEncrypt();
        }

        public List<Sys_File> GetFilesForThumbnail(List<int> Ids)
        {
            var sql = @" Select Id,FileUrl,Thumbnail,Content,FileType,IP,ContentType From sys_file Where Id IN @Ids ";
            return Query<Sys_File>(sql, new { Ids = Ids }).ToList().DeEncrypt();
        }

        public int InsertFile(Sys_File model)
        {
            model.Encrypt();
            var sql = @" INSERT INTO `sys_file`(`FileUrl`, `Content`, `Thumbnail`, `FileType`, `IP`, `ContentType`) VALUES (@FileUrl, @Content, @Thumbnail, @FileType, @IP, @ContentType) ";
            return Insert(sql, model);
        }

        public int PerformSql(string sql)
        {
            try
            {
                return Execute(sql);
            }
            catch (System.Exception e)
            {
                return 0;
            }
        }

        public List<Pub_Pat_Info> GetPatList()
        {
            var sql = @" select * from pub_pat_info where PHONE_NO like '%2a0af7fef216d66199096a7316beb56979d2d214%' ";
            return Query<Pub_Pat_Info>(sql).ToList().DeEncrypt();
        }

        public int UpdatePat(List<Pub_Pat_Info> ls)
        {
            var sql = @" UPDATE pub_pat_info SET PHONE_NO = @Phone_NO 
                        WHERE ID = @Id  ";
            return Execute(sql, ls);
        }
    }
}
