<?php

declare(strict_types=1);

namespace App\Models;

use App\Core\Model;
use PDO;

/**
 * Franchisee Model
 *
 * Handles franchise inquiry/application records with
 * status-based filtering (pending, approved, rejected).
 */
class Franchisee extends Model
{
    /**
     * The database table associated with the model.
     */
    protected string $table = 'franchisees';

    /**
     * Get all pending franchise applications.
     *
     * @return array<int, array<string, mixed>> Array of pending franchise records
     */
    public function getPending(): array
    {
        return $this->getByStatus('pending');
    }

    /**
     * Get franchise applications filtered by status.
     *
     * @param string $status The status to filter by ('pending', 'approved', 'rejected')
     * @return array<int, array<string, mixed>> Array of franchise records matching the status
     */
    public function getByStatus(string $status): array
    {
        $sql = sprintf(
            'SELECT * FROM `%s` WHERE `status` = :status ORDER BY `created_at` DESC',
            $this->table
        );

        $stmt = $this->db->prepare($sql);
        $stmt->execute([':status' => $status]);

        return $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
    }
}
