using IRaCIS.Application.Contracts;
using IRaCIS.Application.Interfaces;
using Microsoft.AspNetCore.Mvc;

namespace IRaCIS.Core.Application.Service
{
    [ApiExplorerSettings(GroupName = "Reviewer")]
    public class ResearchPublicationService(IRepository<ResearchPublication> _researchPublicationRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, IResearchPublicationService
    {


        /// <summary>
        /// 查询-医生科学研究信息
        /// </summary>
        /// <param name="doctorId">医生Id</param>
        /// <returns></returns>
        [HttpGet("{doctorId:guid}")]
        public async Task<ResearchPublicationDTO> GetResearchPublication(Guid doctorId)
        {
            var doctorScientificResearchInfo = await _researchPublicationRepository.Where(o => o.DoctorId == doctorId)
                .ProjectTo<ResearchPublicationDTO>(_mapper.ConfigurationProvider).FirstOrDefaultAsync();
            return doctorScientificResearchInfo!;
        }


        [HttpPost]
        public async Task<IResponseOutput> AddOrUpdateResearchPublication(ResearchPublicationDTO param)
        {

            var entity = await _researchPublicationRepository.InsertOrUpdateAsync(param, true);

            return ResponseOutput.Ok(entity.Id);
        }

        /// <summary>
        /// 新增或修改ResearchPublication  传null不修改
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> AddOrUpdateResearchPublicationInfo(ResearchPublicationInfoDTO param)
        {
            var entity = await _researchPublicationRepository.InsertOrUpdateAsync(param, true);

            return ResponseOutput.Ok(entity.Id);
        }
    }
}