<?php
declare(strict_types=1);

namespace App\Modules\Pricing\Models;

use App\Core\Model;
use App\Core\App;

class PricingConfig extends Model
{
    protected static string $table = 'pricing_configs';
    protected static bool $softDelete = false;
    protected static bool $timestamps = true;
    protected static array $fillable = [
        'branch_id', 'qualification_id', 'membership_type', 'price', 'currency',
        'effective_from', 'effective_to', 'is_active', 'notes',
    ];

    public static function allWithDetails(): array
    {
        $db = App::getInstance()->db();
        return $db->select("
            SELECT pc.*, b.name_ar as branch_name, q.name_ar as qualification_name
            FROM pricing_configs pc
            JOIN branches b ON b.id = pc.branch_id
            JOIN qualifications q ON q.id = pc.qualification_id
            WHERE pc.is_active = 1
            ORDER BY b.name_ar, q.sort_order, pc.effective_from DESC
        ");
    }
}