from verify_agent import create_verifier


def create_accepted_verifier(accepted_trids, **options):
    verify_request = create_verifier(**options)

    def check(method, public_origin, target, headers, raw_body):
        result = verify_request(method, public_origin, target, headers, raw_body)
        if not result['ok'] or result.get('tokenRequestorId') in accepted_trids:
            return result
        return {'ok': False, 'code': 'tap_key_unknown', 'reason': 'trid_not_accepted', 'message': "The key is listed in Visa's directory under a TRID this service doesn't accept.", 'judged': True, 'status': 403, 'retryAfterSeconds': None}

    return check
