/*-
 * ============LICENSE_START=======================================================
 * ONAP POLICY-CLAMP
 * ================================================================================
 * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * 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.
 * ============LICENSE_END============================================
 * ===================================================================
 *
 */

export default class PolicyService {
  static getPoliciesList() {
    return fetch(window.location.pathname + 'restservices/clds/v2/policies', {
        method: 'GET',
        credentials: 'same-origin'
        })
      .then(function (response) {
        console.debug("getPoliciesList response received: ", response.status);
        if (response.ok) {
          return response.json();
        } else {
          console.error("getPoliciesList query failed");
          return {};
        }
      })
      .catch(function (error) {
        console.error("getPoliciesList error received", error);
        return {};
      });
  }
  static createNewPolicy(policyModelType, policyModelVersion, policyJson) {
    return fetch(window.location.pathname + 'restservices/clds/v2/policies/' + policyModelType + '/' + policyModelVersion, {
            method: 'POST',
            credentials: 'same-origin',
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(policyJson)
        })
      .then(function (response) {
        console.debug("createNewPolicy response received: ", response.status);
        if (response.ok) {
          return response.text;
        } else {
          console.error("createNewPolicy query failed");
          return "";
        }
      })
      .catch(function (error) {
        console.error("createNewPolicy error received", error);
        throw new Error(error)
      });
  }
}
