import { apiGet, apiPost } from "../client";

export const scriptsApi = {
  actionsList(options) {
    return apiGet("/api/v1/scripts/actions/list", options);
  },

  actionByAlias(alias, options) {
    return apiGet(`/api/v1/scripts/actions/alias/${encodeURIComponent(alias)}`, options);
  },

  regularList(options) {
    return apiGet("/api/v1/scripts/regular/list", options);
  },

  scopesList(options) {
    return apiGet("/api/v1/scripts/scopes/list", options);
  },

  runAction(alias, params = {}) {
    return apiPost("/api/v1/scripts/actions/run", { alias, params });
  },

  setActionState(alias, enabled) {
    return apiGet(`/api/v1/scripts/actions/alias/${encodeURIComponent(alias)}/${enabled ? "enable" : "disable"}`);
  },

  setRegularState(alias, enabled) {
    return apiGet(`/api/v1/scripts/regular/alias/${encodeURIComponent(alias)}/${enabled ? "enable" : "disable"}`);
  },

  setScopeState(name, enabled) {
    return apiGet(`/api/v1/scripts/scopes/name/${encodeURIComponent(name)}/${enabled ? "enable" : "disable"}`);
  },

  scopeCode(name, options) {
    return apiGet(`/api/v1/scripts/scopes/name/${encodeURIComponent(name)}`, options);
  },

  placeInArea(payload) {
    return apiPost("/api/v1/scripts/place-in-area", payload);
  },

  unassign(id) {
    return apiGet(`/api/v1/scripts/id/${encodeURIComponent(String(id))}/unassign-from-area`);
  },
};
