<?php

declare(strict_types=1);

namespace App\Modules\Sales\Application\Services;

use App\Core\Request;

final class SalesRouteContext
{
    public function isSalesRoute(): bool
    {
        return str_starts_with(Request::path(), '/sales/');
    }

    public function dashboardCrumb(): array
    {
        return ['label' => 'لوحة التحكم', 'url' => '/admin/dashboard'];
    }

    public function salesBoardPath(): string
    {
        return '/sales/invoices';
    }

    public function invoicesPath(): string
    {
        return '/sales/invoices';
    }

    public function invoiceFormPath(int $id = 0): string
    {
        $base = '/sales/invoices/form';
        return $id > 0 ? $base . '?id=' . $id : $base;
    }

    public function invoiceViewPath(int $id = 0): string
    {
        $base = '/sales/invoices/view';
        return $id > 0 ? $base . '?id=' . $id : $base;
    }

    public function returnsPath(): string
    {
        return '/sales/returns';
    }

    public function returnFormPath(int $id = 0, int $invoiceId = 0): string
    {
        $base = '/sales/returns/form';
        $params = [];
        if ($id > 0) $params[] = 'id=' . $id;
        if ($invoiceId > 0) $params[] = 'invoice_id=' . $invoiceId;
        return $params ? $base . '?' . implode('&', $params) : $base;
    }

    public function returnViewPath(int $id = 0): string
    {
        $base = '/sales/returns/view';
        return $id > 0 ? $base . '?id=' . $id : $base;
    }

    public function quotationsPath(): string
    {
        return '/sales/quotations';
    }

    public function quotationFormPath(int $id = 0): string
    {
        $base = '/sales/quotations/form';
        return $id > 0 ? $base . '?id=' . $id : $base;
    }

    public function quotationViewPath(int $id = 0): string
    {
        $base = '/sales/quotations/view';
        return $id > 0 ? $base . '?id=' . $id : $base;
    }

    public function quotationConvertPath(int $id = 0): string
    {
        $base = '/sales/quotations/convert';
        return $id > 0 ? $base . '?id=' . $id : $base;
    }

    public function quotationEmailPath(int $id = 0): string
    {
        $base = '/sales/quotations/email';
        return $id > 0 ? $base . '?id=' . $id : $base;
    }

    public function quotationWhatsappPath(int $id = 0): string
    {
        $base = '/sales/quotations/whatsapp';
        return $id > 0 ? $base . '?id=' . $id : $base;
    }
}
