using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Serilog;
using XdCxRhDw.Dto;
using XdCxRhDW.App.Api;
using XdCxRhDW.Core.Api;
using XdCxRhDW.Dto;
namespace XdCxRhDW.WebApi.Controllers
{
    /// 
    /// 星历推算功能相关接口
    /// 
    public class XlController : BaseController
    {
        /// 
        /// 推算某个时间点星历
        /// 
        /// 推算参数
        /// 
        [HttpPost]
        public AjaxResult Calc(XlCalcDto dto)
        {
            try
            {
                var p = EphHelper.Calc(dto.tleStr, dto.dt);
                return Success(new SatEphDto()
                {
                    SatId = p.SatId,
                    SatTime = p.SatTime,
                    TleTime = p.TleTime,
                    X = p.X,
                    Y = p.Y,
                    Z = p.Z,
                    VX = p.VX,
                    VY = p.VY,
                    VZ = p.VZ,
                });
            }
            catch (Exception ex)
            {
                return Error(ex.Message);
            }
        }
        /// 
        /// 推算某个时间段星星历
        /// 
        /// 推算参数
        /// 
        [HttpPost]
        public AjaxResult> CalcMult(XlCalcMultDto dto)
        {
            try
            {
                var eph = EphHelper.CalcMult(dto.tleStr, dto.start, dto.end, dto.spanSeconds);
                return Success(eph.Select(p => new EphResDto()
                {
                    SatId = p.SatId,
                    SatTime = p.SatTime,
                    TleTime = p.TleTime,
                    X = p.X,
                    Y = p.Y,
                    Z = p.Z,
                    VX = p.VX,
                    VY = p.VY,
                    VZ = p.VZ,
                }).ToList());
            }
            catch (Exception ex)
            {
                return Error>(ex.Message);
            }
        }
    }
}