using DapperORM;
using PushInfo.Act.IDAL;
using System;
using DapperORM.Common.Models;
using PushInfo.Act.Models.Tables;
using PushInfo.Act.Models.QueryResults;
using System.Collections.Generic;

namespace PushInfo.Act.DAL.MySql
{
    internal class SysPushDAL : BaseRepository<Sys_Push>, ISysPushDAL
    {
        public ResultModel DeleteSysPush(string id)
        {
            return LogicalDeleteAsync<Sys_Push>(x => x.Id == id).Result;
        }

        public ResultModel<Sys_Push> GetSysPush(string id)
        {
            return GetAsync<Sys_Push>(x => x.Id == id).Result;
        }

        public PageListModel<Sys_Push> GetSysPushListByPage(int pageIndex,string projectId)
        {
            string selectSql = @"select Id,Name_Des,Push_Target,Push_Style,Push_Title,Push_Body,Push_Type,Push_Cycle,Push_Month,Push_Which,Push_Action,Push_ActionType,Push_IosLink,Push_AndLink,Push_WebLink,Push_WechatLink,create_time 
                                   from sys_push 
                                  where Is_Deleted = 0 and PushSys_ProId = @projectId";
            string totalSql = @"select count(*) from sys_push where Is_Deleted = 0 and PushSys_ProId = @projectId";
            Dictionary<string, object> condition = new Dictionary<string, object>{ { "@projectId", projectId } };
            return PagedFetchAsync<Sys_Push>(selectSql, totalSql, condition, pageIndex,10).Result;
        }

        public ResultModel SaveSysPush(Sys_Push pushConfig)
        {
            return InsertAsync<Sys_Push>(pushConfig).Result;
        }

        public ResultModel UpdateSysPush(Sys_Push pushConfig)
        {

            return UpdatePartailAsync<Sys_Push>(pushConfig, x => new { x.Push_Action, x.Push_ActionType, x.Push_AndLink, x.Push_Body, x.Push_Cycle, x.Push_IosLink, x.Push_Month, x.Push_Style, x.Push_Target, x.Push_Title, x.Push_Type, x.Push_WebLink,x.Push_WechatLink, x.Push_Which, x.Update_User, x.Update_Time,x.Db_ConnectId,x.Push_User_Action,x.Push_User_ActionType,x.Db_User_ConnectId },x=>x.Id == pushConfig.Id).Result;
        }
        
    }
}
