package com.cameleer.server.core.runtime;

import java.util.List;
import java.util.Map;

public record ResolvedContainerConfig(
        int memoryLimitMb,
        Integer memoryReserveMb,
        int cpuRequest,
        Integer cpuLimit,
        int appPort,
        List<Integer> exposedPorts,
        Map<String, String> customEnvVars,
        boolean stripPathPrefix,
        boolean sslOffloading,
        String routingMode,
        String routingDomain,
        String serverUrl,
        int replicas,
        String deploymentStrategy,
        boolean routeControlEnabled,
        boolean replayEnabled,
        String runtimeType,
        String customArgs,
        List<String> extraNetworks,
        boolean externalRouting,
        String certResolver
) {
    public long memoryLimitBytes() {
        return (long) memoryLimitMb * 1024 * 1024;
    }

    public Long memoryReserveBytes() {
        return memoryReserveMb != null ? (long) memoryReserveMb * 1024 * 1024 : null;
    }

    /** Convert cpuRequest (millicores) to Docker CPU shares (proportional to 1024 = 1 core). */
    public int dockerCpuShares() {
        return cpuRequest * 1024 / 1000;
    }

    /** Convert cpuLimit (millicores) to Docker CPU quota (microseconds per 100ms period). */
    public Long dockerCpuQuota() {
        return cpuLimit != null ? (long) cpuLimit * 100 : null;
    }
}
