package producer

import (
	"math"
	"time"

	"github.com/starainrt/astro/sun"
)

// Azimuth 太阳方位角
// 返回给定经纬度、对应date时区date时刻的太阳方位角（正北为0，向东增加）
func SunAzimuth(date time.Time, lon, lat float64) float64 {
	return sun.Azimuth(date, lon, lat)
}

// Zenith 太阳高度角
// 返回给定经纬度、对应date时区date时刻的太阳高度角
func SunZenith(date time.Time, lon, lat float64) float64 {
	return sun.Zenith(date, lon, lat)
}

func SatAzimuth(lon, lat, lonSat, latSat float64) float64 {
	lon = lon * math.Pi / 180
	lat = lat * math.Pi / 180
	lonSat = lonSat * math.Pi / 180
	latSat = latSat * math.Pi / 180

	beta := math.Acos(math.Cos(lat-latSat) * math.Cos(lon-lonSat))
	phi := math.Asin(math.Sin(lonSat-lon) / math.Sin(beta))
	return phi * 180 / math.Pi
}

func SatZenith(lon, lat, lonSat, latSat float64) float64 {
	lon = lon * math.Pi / 180
	lat = lat * math.Pi / 180
	lonSat = lonSat * math.Pi / 180
	latSat = latSat * math.Pi / 180

	beta := math.Acos(math.Cos(lat-latSat) * math.Cos(lon-lonSat))
	theta := math.Asin(42164.0 * math.Sin(beta) / math.Sqrt(1.8084*1e9-5.3725*1e8*math.Cos(beta)))
	return theta * 180 / math.Pi
}
