using Electricity.Api.Extensions;

namespace Electricity.Api.Models;

public record Minute(uint DateTime, double CurrentPowerUsage, double TotalPowerUse, double TotalPowerReturn, double TotalGasUse)
{
    public static Minute Empty(DateOnly date)
    {
        return new Minute(
            date.ToDateTime(new TimeOnly(0, 0), DateTimeKind.Utc).ToEpoch(),
            0, 0, 0, 0);
    }

    public static Minute FromEntity(Entities.ElectricityLog entity)
    {
        return new Minute(
            DateTime: entity.GetDateTime().ToEpoch(),
            CurrentPowerUsage: entity.CurrentPowerUsage,
            TotalPowerUse: entity.TotalPowerConsumptionDay + entity.TotalPowerConsumptionNight,
            TotalPowerReturn: entity.TotalPowerReturnDay + entity.TotalPowerReturnNight,
            TotalGasUse: entity.GasConsumptionInCubicMeters
        );
    }
};