/*
 * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
 *
 * WSO2 LLC. licenses this file to you 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.
 */

package org.wso2.carbon.is.migration.service.v710.constants;

public class XACMLSQLConstants {

    private XACMLSQLConstants() {

    }

    // Config related queries
    public static final String GET_POLICY_COMBINING_ALGORITHM_SQL =
            "SELECT CONFIG_VALUE FROM IDN_XACML_CONFIG WHERE CONFIG_KEY=:CONFIG_KEY; AND TENANT_ID=:TENANT_ID;";
    public static final String CREATE_POLICY_COMBINING_ALGORITHM_SQL = "INSERT INTO IDN_XACML_CONFIG " +
            "(CONFIG_KEY, CONFIG_VALUE, TENANT_ID) VALUES (:CONFIG_KEY;, :CONFIG_VALUE;, :TENANT_ID;)";

    // Subscriber related queries
    public static final String LIST_SUBSCRIBER_IDS_SQL = "SELECT DISTINCT SUBSCRIBER_ID FROM IDN_XACML_SUBSCRIBER " +
            "WHERE TENANT_ID=:TENANT_ID;";
    public static final String CREATE_SUBSCRIBER_SQL = "INSERT INTO IDN_XACML_SUBSCRIBER (SUBSCRIBER_ID, " +
            "ENTITLEMENT_MODULE_NAME, TENANT_ID) VALUES (:SUBSCRIBER_ID;, :ENTITLEMENT_MODULE_NAME;, :TENANT_ID;)";
    public static final String CREATE_SUBSCRIBER_PROPERTIES_SQL = "INSERT INTO IDN_XACML_SUBSCRIBER_PROPERTY " +
            "(PROPERTY_ID, DISPLAY_NAME, PROPERTY_VALUE, IS_REQUIRED, DISPLAY_ORDER, IS_SECRET, " +
            "PROPERTY_MODULE, SUBSCRIBER_ID, TENANT_ID) VALUES (:PROPERTY_ID;, :DISPLAY_NAME;, :PROPERTY_VALUE;, " +
            ":IS_REQUIRED;, :DISPLAY_ORDER;, :IS_SECRET;, :PROPERTY_MODULE;, :SUBSCRIBER_ID;, :TENANT_ID;)";

    // Status related queries
    public static final String LIST_POLICY_IDS_WITH_STATUS_SQL = "SELECT DISTINCT POLICY_ID FROM " +
            "IDN_XACML_POLICY_STATUS WHERE TENANT_ID=:TENANT_ID;";
    public static final String LIST_SUBSCRIBER_IDS_WITH_STATUS_SQL = "SELECT DISTINCT SUBSCRIBER_ID FROM " +
            "IDN_XACML_SUBSCRIBER_STATUS WHERE TENANT_ID=:TENANT_ID;";
    public static final String CREATE_POLICY_STATUS_SQL = "INSERT INTO IDN_XACML_POLICY_STATUS (TYPE, IS_SUCCESS, " +
            "USERNAME, TARGET, TARGET_ACTION, LOGGED_AT, MESSAGE, POLICY_ID, POLICY_VERSION, TENANT_ID) " +
            "VALUES (:TYPE;, :IS_SUCCESS;, :USERNAME;, :TARGET;, :TARGET_ACTION;, :LOGGED_AT;, :MESSAGE;, " +
            ":KEY;, :VERSION;, :TENANT_ID;)";
    public static final String CREATE_SUBSCRIBER_STATUS_SQL = "INSERT INTO IDN_XACML_SUBSCRIBER_STATUS " +
            "(TYPE, IS_SUCCESS, USERNAME, TARGET, TARGET_ACTION, LOGGED_AT, MESSAGE, SUBSCRIBER_ID, " +
            "TENANT_ID) VALUES (:TYPE;, :IS_SUCCESS;, :USERNAME;, :TARGET;, :TARGET_ACTION;, :LOGGED_AT;, " +
            ":MESSAGE;, :KEY;, :TENANT_ID;)";

    // Policy related queries
    public static final String LIST_POLICY_IDS_SQL = "SELECT DISTINCT POLICY_ID FROM IDN_XACML_POLICY WHERE " +
            "TENANT_ID= :TENANT_ID;";
    public static final String CREATE_POLICY_SQL = "INSERT INTO IDN_XACML_POLICY (POLICY_ID, VERSION, " +
            " IS_IN_PDP, IS_IN_PAP, POLICY, IS_ACTIVE, POLICY_TYPE, POLICY_EDITOR, POLICY_ORDER, " +
            "LAST_MODIFIED_TIME, LAST_MODIFIED_USER, TENANT_ID) VALUES (:POLICY_ID;, :VERSION;, :IS_IN_PDP;, " +
            ":IS_IN_PAP;, :POLICY;, :IS_ACTIVE;, :POLICY_TYPE;, :POLICY_EDITOR;, :POLICY_ORDER;, " +
            ":LAST_MODIFIED_TIME;, :LAST_MODIFIED_USER;, :TENANT_ID;)";
    public static final String CREATE_POLICY_REFS_SQL = "INSERT INTO IDN_XACML_POLICY_REFERENCE " +
            "(REFERENCE, POLICY_ID, VERSION, TENANT_ID) VALUES (:REFERENCE;, :POLICY_ID;, :VERSION;, :TENANT_ID;)";
    public static final String CREATE_POLICY_SET_REFS_SQL = "INSERT INTO IDN_XACML_POLICY_SET_REFERENCE " +
            "(SET_REFERENCE, POLICY_ID, VERSION, TENANT_ID) VALUES (:SET_REFERENCE;, :POLICY_ID;, :VERSION;, " +
            ":TENANT_ID;)";
    public static final String CREATE_POLICY_ATTRIBUTES_SQL = "INSERT INTO IDN_XACML_POLICY_ATTRIBUTE " +
            "(ATTRIBUTE_ID, ATTRIBUTE_VALUE, DATA_TYPE, CATEGORY, POLICY_ID, VERSION, TENANT_ID) VALUES " +
            "(:ATTRIBUTE_ID;, :ATTRIBUTE_VALUE;, :DATA_TYPE;, :CATEGORY;, :POLICY_ID;, :VERSION;, :TENANT_ID;)";
    public static final String CREATE_POLICY_EDITOR_DATA_SQL = "INSERT INTO IDN_XACML_POLICY_EDITOR_DATA " +
            "(DATA_ORDER, DATA, POLICY_ID, VERSION, TENANT_ID) VALUES (:DATA_ORDER;, :DATA;, :POLICY_ID;, " +
            ":VERSION;, :TENANT_ID;)";

    public static class XACMLTableColumns {

        private XACMLTableColumns() {

        }

        public static final String TENANT_ID = "TENANT_ID";
        public static final String CONFIG_KEY = "CONFIG_KEY";
        public static final String CONFIG_VALUE = "CONFIG_VALUE";
        public static final String SUBSCRIBER_ID = "SUBSCRIBER_ID";
        public static final String ENTITLEMENT_MODULE_NAME = "ENTITLEMENT_MODULE_NAME";
        public static final String PROPERTY_ID = "PROPERTY_ID";
        public static final String DISPLAY_NAME = "DISPLAY_NAME";
        public static final String IS_REQUIRED = "IS_REQUIRED";
        public static final String DISPLAY_ORDER = "DISPLAY_ORDER";
        public static final String IS_SECRET = "IS_SECRET";
        public static final String MODULE = "PROPERTY_MODULE";
        public static final String PROPERTY_VALUE = "PROPERTY_VALUE";
        public static final String KEY = "KEY";
        public static final String STATUS_TYPE = "TYPE";
        public static final String IS_SUCCESS = "IS_SUCCESS";
        public static final String USER = "USERNAME";
        public static final String TARGET = "TARGET";
        public static final String TARGET_ACTION = "TARGET_ACTION";
        public static final String LOGGED_AT = "LOGGED_AT";
        public static final String MESSAGE = "MESSAGE";
        public static final String VERSION = "VERSION";
        public static final String POLICY_ID = "POLICY_ID";
        public static final String LAST_MODIFIED_TIME = "LAST_MODIFIED_TIME";
        public static final String LAST_MODIFIED_USER = "LAST_MODIFIED_USER";
        public static final String IS_ACTIVE = "IS_ACTIVE";
        public static final String POLICY_ORDER = "POLICY_ORDER";
        public static final String POLICY_TYPE = "POLICY_TYPE";
        public static final String POLICY_EDITOR = "POLICY_EDITOR";
        public static final String POLICY = "POLICY";
        public static final String IS_IN_PAP = "IS_IN_PAP";
        public static final String IS_IN_PDP = "IS_IN_PDP";
        public static final String EDITOR_DATA_ORDER = "DATA_ORDER";
        public static final String EDITOR_DATA = "DATA";
        public static final String ATTRIBUTE_ID = "ATTRIBUTE_ID";
        public static final String ATTRIBUTE_VALUE = "ATTRIBUTE_VALUE";
        public static final String DATA_TYPE = "DATA_TYPE";
        public static final String CATEGORY = "CATEGORY";
        public static final String REFERENCE = "REFERENCE";
        public static final String SET_REFERENCE = "SET_REFERENCE";
    }
}
