<?php
declare(strict_types=1);

namespace App\Models;

use Core\DB;
use Core\Model;

final class Tenant extends Model
{
    protected string $table = 'tenants';
    protected string $primaryKey = 'tenant_id';

    /** All active tenants — used by the login dropdown (Option 1). */
    public static function activeForLogin(): array
    {
        return DB::all(
            'SELECT tenant_id, name, subdomain
               FROM tenants
              WHERE status = :st AND deleted_at IS NULL
              ORDER BY name'
            , ['st' => 'active']
        );
    }

    public static function findById(int $id): ?array
    {
        return DB::one(
            'SELECT * FROM tenants WHERE tenant_id = :id AND deleted_at IS NULL',
            ['id' => $id]
        );
    }
}
