using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
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 PubQuestReleaseRepository : BaseRepositoryToASHermed_SinoInterface<Pub_Quest_Release>, IPubQuestReleaseRepository
    {
        public async Task<int> InsertAnReturnIdAsync(Pub_Quest_Release release)
        {
            const string sql = @" INSERT INTO `pub_quest_release` ( `QuestInfoId`, `QuestInfoName`, `QuestInfoNameEN`, `QuestInfoNameGE`, `Content`, `Version`, `CreateTime`, `CreateUser` )
                            VALUES
	                                                              ( @QuestInfoId, @QuestInfoName, @QuestInfoNameEN, @QuestInfoNameGE, @Content, @Version, @CreateTime, @CreateUser ) ";

            return await InsertAsync(sql, release);
        }

        public async Task<Pub_Quest_Release> GetByIdAsync(int infoId, decimal version)
        {
            var sql = @" select * from pub_quest_release where QuestInfoId=@QuestInfoId And Version=@Version ";
            var result = await QueryAsync<Pub_Quest_Release>(sql, new { QuestInfoId = infoId, Version = version });
            return result?.FirstOrDefault();
        }
    }
}
