package service

import (
	"context"
	"time"

	"go.uber.org/zap"
)

type Service struct {
	cfg    *Config
	redis  Redis
	grib   Grib
	logger *zap.Logger
}

func New(cfg *Config, gribService Grib, redisService Redis, logger *zap.Logger) (*Service, error) {
	svc := &Service{
		cfg:    cfg,
		redis:  redisService,
		grib:   gribService,
		logger: logger,
	}

	return svc, nil
}

// UpdateWeatherData updates weather forecast data using the configured grib service
func (s *Service) UpdateWeatherData(ctx context.Context) error {
	return s.grib.Update(ctx)
}

// ExtractWind extracts wind data for given coordinates and time
func (s *Service) ExtractWind(ctx context.Context, lat, lon, alt float64, ts time.Time) ([2]float64, error) {
	return s.grib.Extract(ctx, lat, lon, alt, ts)
}

// Update updates the GRIB data (implements updater.GribService)
func (s *Service) Update(ctx context.Context) error {
	return s.UpdateWeatherData(ctx)
}

// Start starts the service
func (s *Service) Start() {
	s.logger.Info("service started")
}

// Stop stops the service
func (s *Service) Stop() {
	s.logger.Info("service stopped")
}

// Close closes the service and releases resources
func (s *Service) Close() error {
	s.Stop()
	return nil
}
