<?php

use App\Core\Database;

if (!function_exists('ec_submission_stage')) {

function ec_submission_stage(
int $submissionId
): string
{

$db=
Database::getInstance();

$q=
$db->prepare("
SELECT
COALESCE(
workflow_stage,
status,
'submitted'
)
FROM submissions
WHERE id=?
LIMIT 1
");

$q->execute([
$submissionId
]);

return
(string)(
$q->fetchColumn()
?: 'submitted'
);

}

}

if (!function_exists('ec_can_edit_submission')) {

function ec_can_edit_submission(
int $submissionId
): bool
{

$stage=
ec_submission_stage(
$submissionId
);

return
in_array(
$stage,
[
'submitted',
'revision_required',
'resubmitted'
],
true
);

}

}

if (!function_exists('ec_can_review_submission')) {

function ec_can_review_submission(
int $submissionId
): bool
{

return
ec_submission_stage(
$submissionId
)
===
'under_review';

}

}

if (!function_exists('ec_can_decide_submission')) {

function ec_can_decide_submission(
int $submissionId
): bool
{

return
in_array(
ec_submission_stage(
$submissionId
),
[
'under_review',
'resubmitted'
],
true
);

}

}

