using SatelliteProvider.Common.DTO;
using SatelliteProvider.DataAccess.Models;

namespace SatelliteProvider.Services.RouteManagement;

public class RouteResponseMapper
{
    public RouteResponse Map(RouteEntity route, IEnumerable<RoutePointDto> points)
    {
        ArgumentNullException.ThrowIfNull(route);
        ArgumentNullException.ThrowIfNull(points);

        var pointList = points as List<RoutePointDto> ?? points.ToList();

        return new RouteResponse
        {
            Id = route.Id,
            Name = route.Name,
            Description = route.Description,
            RegionSizeMeters = route.RegionSizeMeters,
            ZoomLevel = route.ZoomLevel,
            TotalDistanceMeters = route.TotalDistanceMeters,
            TotalPoints = route.TotalPoints,
            Points = pointList,
            RequestMaps = route.RequestMaps,
            MapsReady = route.MapsReady,
            CsvFilePath = route.CsvFilePath,
            SummaryFilePath = route.SummaryFilePath,
            StitchedImagePath = route.StitchedImagePath,
            TilesZipPath = route.TilesZipPath,
            CreatedAt = route.CreatedAt,
            UpdatedAt = route.UpdatedAt,
        };
    }

    public RouteResponse Map(RouteEntity route, IEnumerable<RoutePointEntity> entities)
    {
        ArgumentNullException.ThrowIfNull(entities);
        var pointDtos = entities.Select(p => new RoutePointDto
        {
            Latitude = p.Latitude,
            Longitude = p.Longitude,
            PointType = p.PointType,
            SequenceNumber = p.SequenceNumber,
            SegmentIndex = p.SegmentIndex,
            DistanceFromPrevious = p.DistanceFromPrevious,
        }).ToList();
        return Map(route, pointDtos);
    }
}
