<?php
namespace IMSGlobal\LTI;

class Submission_Review_Message_Validator implements Message_Validator {
    public function can_validate(array $jwt_body): bool {
        return $jwt_body['https://purl.imsglobal.org/spec/lti/claim/message_type'] === 'LtiSubmissionReviewRequest';
    }

    public function validate(array $jwt_body): bool {
        if (empty($jwt_body['sub'])) {
            throw new LTI_Exception('Must have a user (sub)');
        }
        if ($jwt_body['https://purl.imsglobal.org/spec/lti/claim/version'] !== '1.3.0') {
            throw new LTI_Exception('Incorrect version, expected 1.3.0');
        }
        if (!isset($jwt_body['https://purl.imsglobal.org/spec/lti/claim/roles'])) {
            throw new LTI_Exception('Missing Roles Claim');
        }
        if (empty($jwt_body['https://purl.imsglobal.org/spec/lti/claim/resource_link']['id'])) {
            throw new LTI_Exception('Missing Resource Link Id');
        }
        if (empty($jwt_body['https://purl.imsglobal.org/spec/lti/claim/for_user'])) {
            throw new LTI_Exception('Missing For User');
        }

        return true;
    }
}
