<?php

namespace App\EventHooks\System;

use App\EventHooks\HookEvent;
use App\Models\Order;

/**
 * Fire noktası: Store\CheckoutController — mesafeli satış (custom tip)
 * sözleşmesi onaylanınca 'DistanceSellingContractAccepted' hook'u.
 * Context: order_id/orderid, client_id, contract_id, contract_title.
 */
class ContractAccepted extends HookEvent
{
    public const HOOK = 'DistanceSellingContractAccepted';

    public function orderId(): ?int
    {
        $id = $this->get('order_id') ?? $this->get('orderid');

        return $id ? (int) $id : null;
    }

    public function order(): ?Order
    {
        $id = $this->orderId();

        return $id ? Order::find($id) : null;
    }

    public function contractTitle(): ?string
    {
        return $this->get('contract_title');
    }
}
