<?php
// Quote calculator for a sample cleaning business. Prices in cents to avoid rounding drift.
declare(strict_types=1);
const RATES = ['standard' => 450, 'deep' => 720, 'end_of_lease' => 950];   // cents per square metre
const EXTRAS = ['oven' => 6500, 'windows' => 4000, 'carpet_room' => 3500];  // cents each
const MINIMUM = 12000; const TAX_RATE = 0.10; const WEEKLY_DISCOUNT = 0.15; const FORTNIGHTLY_DISCOUNT = 0.10;
function quote(int $sqm, string $service, array $extras = [], string $frequency = 'once'): array {
    if ($sqm < 20 || $sqm > 800) throw new InvalidArgumentException('Area must be 20 to 800 m²');
    if (!isset(RATES[$service])) throw new InvalidArgumentException('Unknown service');
    $base = max(MINIMUM, $sqm * RATES[$service]); $ext = 0;
    foreach ($extras as $name => $qty) { if (!isset(EXTRAS[$name])) throw new InvalidArgumentException("Unknown extra: $name"); $ext += EXTRAS[$name] * $qty; }
    $disc = match ($frequency) { 'weekly' => WEEKLY_DISCOUNT, 'fortnightly' => FORTNIGHTLY_DISCOUNT, 'once' => 0.0, default => throw new InvalidArgumentException('Unknown frequency') };
    if ($service === 'end_of_lease') $disc = 0.0;                       // recurring discount never applies to end-of-lease
    $sub = $base + $ext; $discount = (int)round($sub * $disc); $net = $sub - $discount; $tax = (int)round($net * TAX_RATE);
    return ['base' => $base, 'extras' => $ext, 'discount' => $discount, 'net' => $net, 'tax' => $tax, 'total' => $net + $tax];
}
