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

namespace ASHermed.SinoInterface.Api.MySqlRepository
{
    public class HealthClubRepository : BaseRepositoryToASHermed_SinoInterface<OutHealthClub>, IHealthClubRepository
    {
        public OutHealthClub SelectByPhone(string phone)
        {
            var selectSql = new StringBuilder();
            var parms = new Dictionary<string, object>();
            selectSql.Append(@" select ID, NICK_NAME, PHONE, TAG_ID, STATES, CREATE_USER, CREATE_TIME
                                from out_health_club
                                where PHONE = @phone
                                  and STATES = 1
                                order by CREATE_TIME desc
                                limit 0,1");
            parms.Add("@phone", phone);
            var result = Query<OutHealthClub>(selectSql.ToString(), parms);
            return result?.FirstOrDefault();
        }

        public async Task<List<Pub_Club_Vedio>> GetIndexVedio()
        {
            var selectSql = new StringBuilder();
            var parms = new Dictionary<string, object>();
            selectSql.Append(@" select * from Pub_Club_Vedio where `status`=1");
            var result = QueryAsync<Pub_Club_Vedio>(selectSql.ToString(), null);
            return result?.Result?.ToList();
        }

        public int InsertHealthClub(OutHealthClub model)
        {
            StringBuilder str = new StringBuilder();
            str.Append("insert into out_health_club (NICK_NAME,PHONE,TAG_ID,STATES,CREATE_USER,CREATE_TIME)  values (@NICK_NAME,@PHONE,@TAG_ID,@STATES,@CREATE_USER,@CREATE_TIME)");
            var parms = new Dictionary<string, object>();
            parms.Add("@NICK_NAME", model.NickName);
            parms.Add("@PHONE", model.Phone);
            parms.Add("@TAG_ID", model.TagId);
            parms.Add("@STATES", model.States);
            parms.Add("@CREATE_USER", model.CreateUser);
            parms.Add("@CREATE_TIME", DateTime.Now);
            var result = Insert(str.ToString(), parms);
            return result;
        }
    }
}
