<?php

namespace App\Models;

use App\Core\Model;

class FormShare extends Model
{
    protected $table = 'form_shares';
    protected $primaryKey = 'id';

    public function getSharesForForm($formId)
    {
        $stmt = $this->db->prepare("SELECT s.*, u.name as shared_by_name FROM {$this->table} s LEFT JOIN users u ON s.shared_by = u.id WHERE s.form_id = ? ORDER BY s.created_at DESC");
        $stmt->execute([$formId]);
        return $stmt->fetchAll(\PDO::FETCH_OBJ);
    }

    public function generateToken()
    {
        return bin2hex(random_bytes(32));
    }
}
