function csvFile = model1_deterministic_phy_service_time(U, p, csvFile)
% Model 1:
% Deterministic PHY Service-Time Approximation
%
% Inputs  = p + 5
% Output  = 1 (targetDelay)

if nargin < 2, p = 6; end
if nargin < 3 || isempty(csvFile)
    csvFile = 'model1_deterministic_phy_service_time.csv';
end

N = numel(U.packetBytes);

txTimeMs = zeros(N,1);
delayMs = zeros(N,1);

fixedMacOverheadMs = 0.15;
fixedProcMs = 0.05;

for i = 1:N
    cfgHE = wlanHESUConfig;
    cfgHE.ChannelBandwidth = U.channelBandwidth;
    cfgHE.MCS = U.mcs(i);
    cfgHE.APEPLength = U.packetBytes(i);

    fs = wlanSampleRate(cfgHE);

    try
        psduBytes = getPSDULength(cfgHE);
    catch
        psduBytes = cfgHE.APEPLength;
    end

    txBits = randi([0 1], 8*psduBytes, 1);
    txWave = wlanWaveformGenerator(txBits, cfgHE);

    txTimeMs(i) = 1e3 * numel(txWave) / fs;

    delayMs(i) = fixedMacOverheadMs + txTimeMs(i) + fixedProcMs;
end

tbl = table( ...
    U.arrivalGapMs, ...
    U.packetBytes, ...
    U.snrDb, ...
    U.mcs, ...
    txTimeMs, ...
    delayMs, ...
    'VariableNames', { ...
    'arrivalGapMs','packetBytes','snrDb','mcs','txTimeMs','delayMs'});

Treg = make_regression_table(tbl, 'delayMs', p, 1);
writetable(Treg, csvFile);

fprintf('Model 1 CSV saved: %s\n', csvFile);
fprintf('Model 1 inputs = %d, outputs = 1\n', width(Treg)-1);
end
