using Microsoft.AspNetCore.Mvc;
using Nirvana.Common;
using Nirvana.Common.ApiBase;
using YBDevice.Entity;
using YBDevice.NApi.Application.FamilyInfo;

namespace YBDevice.NApi.Controllers
{
    /// <summary>
    /// 家庭成员管理
    /// </summary>
    public class FamilyController : BaseController
    {
        private readonly IFamilyService _familyService;
        private readonly IResultService _resultService;
        public FamilyController(IFamilyService familyService,IResultService resultService)
        {
            _familyService = familyService;
            _resultService = resultService;
        }
        /// <summary>
        /// 家庭成员列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> GetListAsync()
        {
            return await _familyService.GetListAsync();
        }

        /// <summary>
        /// 家庭成员信息修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> SubmitAsync([FromBody] FamilySubmitModel model)
        {
            return await _familyService.SubmitAsync(model);
        }
        /// <summary>
        /// 删除家庭成员
        /// </summary>
        /// <param name="id">家庭成员ID</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> DeleteAsync(int id)
        {
            return await _familyService.DeleteAsync(id);
        }
        /// <summary>
        /// 家庭成员详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> DetailAsync(int id)
        {
            return await _familyService.DetailAsync(id);
        }
        /// <summary>
        /// 设置目标体重
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> SetTargetAsync([FromBody] YB_FamilyTarget model)
        {
            return await _familyService.SetTargetAsync(model);
        }
        /// <summary>
        /// 获取指定家庭成员的历史记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetHistoryListAsync([FromBody] ParamQuery model)
        {
            var data= await _resultService.GetHistoryListAsync(model);
            return new ResultInfo(ResultState.SUCCESS, "success", data);
        }

        /// <summary>
        /// 获取指定家庭成员的八电极历史记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetBodyHistoryListAsync([FromBody] ParamQuery model)
        {
            var data = await _resultService.GetBodyHistoryListAsync(model);
            return new ResultInfo(ResultState.SUCCESS, "success", data);
        }
        /// <summary>
        /// 手动添加的记录列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetAddListAsync([FromBody] ParamQuery model)
        {
            var data = await _resultService.GetAddListAsync(model);
            return new ResultInfo(ResultState.SUCCESS, "success", data);
        }
        /// <summary>
        /// 删除手动添加的记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultInfo> DeleteAddResultAsync(Guid? id =null)
        {
            return await _resultService.DeleteAddResultAsync(id.Value);
        }

        /// <summary>
        /// 家庭成员模式切换
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> SetTypeAsync([FromBody]FamilyTypeSetC2SDto data)
        {
            return await _familyService.SetTypeAsync(data);
        }
    }
}
