<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Cached per-client product list (one row per WHMCS user). The `products`
 * column is the raw GetClientsProducts response so read code can treat it
 * exactly like the live API result.
 *
 * Two refresh paths:
 *   - Lazy: when a TicketServiceContext lookup finds no row OR a row older
 *           than the configured TTL, fetch fresh.
 *   - Scheduled: every 6 h, refresh every row touched by a ticket in the
 *           last 30 days (and any row older than 24 h regardless).
 */
class WhmcsClientProducts extends Model
{
    protected $table = 'whmcs_client_products';

    protected $fillable = [
        'whmcs_user_id', 'products', 'product_count', 'last_synced_at',
    ];

    protected $casts = [
        'products'       => 'array',
        'last_synced_at' => 'datetime',
    ];
}
