<!--
 Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

{% extends 'base.html' %}

{% block content %}
    <h1>Policy Rules</h1>

    <div class="row">
        <div class="col">
            {{ policy_rules | length }} policy rules found in context <i>{{ session['context_uuid'] }}</i>
        </div>
    </div>

    <table class="table table-striped table-hover">
        <thead>
          <tr>
            <th scope="col">UUID</th>
            <th scope="col">Kind</th>
            <th scope="col">Priority</th>
            <th scope="col">Condition</th>
            <th scope="col">Operator</th>
            <th scope="col">Action</th>
            <th scope="col">Service</th>
            <th scope="col">Devices</th>
            <th scope="col">State</th>
            <th scope="col">Message</th>
            <th scope="col">Extra</th>
            <th scope="col"></th>
          </tr>
        </thead>
        <tbody>
            {% if policy_rules %}
                {% for policy_rule in policy_rules %}
                    {% if policy_rule.WhichOneof('policy_rule') == 'device' %}
                        <tr>
                            <td>{{ policy_rule.device.policyRuleBasic.policyRuleId.uuid }}</td>
                            <td>{{ policy_rule.WhichOneof('policy_rule') }}</td>
                            <td>{{ policy_rule.device.policyRuleBasic.priority }}</td>
                            <td>{{ policy_rule.device.policyRuleBasic.conditionList }}</td>
                            <td>{{ policy_rule.device.policyRuleBasic.booleanOperator }}</td>
                            <td>{{ policy_rule.device.policyRuleBasic.actionList }}</td>
                            <td>-</td>
                            <td>{{ policy_rule.device.deviceList }}</td>
                            <td>{{ prse.Name(policy_rule.device.policyRuleBasic.policyRuleState.policyRuleState).replace('POLICY_', '') }}</td>
                            <td>{{ policy_rule.device.policyRuleBasic.policyRuleState.policyRuleStateMessage }}</td>
                        </tr>
                    {% elif policy_rule.WhichOneof('policy_rule') == 'service' %}
                        <tr>
                            <td>{{ policy_rule.service.policyRuleBasic.policyRuleId.uuid }}</td>
                            <td>{{ policy_rule.WhichOneof('policy_rule') }}</td>
                            <td>{{ policy_rule.service.policyRuleBasic.priority }}</td>
                            <td>{{ policy_rule.service.policyRuleBasic.conditionList }}</td>
                            <td>{{ policy_rule.service.policyRuleBasic.booleanOperator }}</td>
                            <td>{{ policy_rule.service.policyRuleBasic.actionList }}</td>
                            <td>{{ policy_rule.service.serviceId }}</td>
                            <td>{{ policy_rule.service.deviceList }}</td>
                            <td>{{ prse.Name(policy_rule.service.policyRuleBasic.policyRuleState.policyRuleState).replace('POLICY_', '') }}</td>
                            <td>{{ policy_rule.service.policyRuleBasic.policyRuleState.policyRuleStateMessage }}</td>
                        </tr>
                    {% else %}
                        <tr><td colspan="11">Unsupported policy rule type {{ policy_rule.WhichOneof('policy_rule') }}</td></tr>
                    {% endif %}
                {% endfor %}
            {% else %}
                <tr><td colspan="11">No policy rule found</td></tr>
            {% endif %}
        </tbody>
    </table>

{% endblock %}
