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

namespace ASHermed.SinoInterface.Api.MySqlRepository.Quest
{
    public class PubQuestCategoryRepository : BaseRepositoryToASHermed_SinoInterface<Pub_Quest_Category>, IPubQuestCategoryRepository
    {
        public async Task<int> InsertAndReturnIdAsync(Pub_Quest_Category questPatTestInfo)
        {
            const string sql = @"INSERT INTO pub_quest_category ( Name, NameEN, NameGE, IsDelete, InfoId, UpdateTime, UpdateUser, CreateTime, CreateUser, Sort)
                                VALUES
                                  	(
                                  		@Name,
                                  		@NameEN,
                                  		@NameGE,
                                  		@IsDelete, @InfoId, @UpdateTime, @UpdateUser, @CreateTime, @CreateUser, @Sort
                                  	)";

            var insertResult = await InsertAsync(sql, questPatTestInfo);

            return insertResult;
        }

        public async Task<List<Pub_Quest_Category>> GetCategorie(List<string> name)
        {
            var sql = @" select * from pub_quest_category where Name in @Names and IsDelete = false ";
            var result = await QueryAsync<Pub_Quest_Category>(sql, new { Names = name });
            return result.ToList();
        }

        public async Task<List<Pub_Quest_Category>> GetCategorieForInfoId(int infoId)
        {
            var sql = @" select * from pub_quest_category where InfoId = @InfoId and IsDelete = false ";
            var result = await QueryAsync<Pub_Quest_Category>(sql, new { InfoId = infoId });
            return result.ToList();
        }

        public async Task<int> UpdateCate(Pub_Quest_Category category)
        {
            var sql = @" UPDATE `pub_quest_category` SET `Name` = @Name, `NameEN` = @NameEN, `NameGE` = @NameGE, `IsDelete` = @IsDelete, `InfoId` = @InfoId, `UpdateTime` = @UpdateTime, `UpdateUser` = @UpdateUser, `CreateTime` = @CreateTime, `CreateUser` = @CreateUser, `Sort` = @Sort WHERE `Id` = @Id ";
            return Execute(sql, category);
        }

        public async Task<int> UpdateSort(int id, int sort)
        {
            var sql = @" UPDATE `pub_quest_category` SET `Sort` = @Sort WHERE `Id` = @Id ";
            return await ExecuteAsync(sql, new { Sort = sort, Id = id });
        }
    }
}
