import { computed } from "vue";
import { useGraphqlBridge } from "../bridges/graphql.js";
export function useGraphqlModelOperation(props) {
  const { graphqlOperation } = useGraphqlBridge();
  function capitalizeFirstLetter(string) {
    return string?.charAt(0).toUpperCase() + string?.slice(1);
  }
  function lowercaseFirstLetter(string) {
    return string?.charAt(0).toLowerCase() + string?.slice(1);
  }
  const computedModelName = computed(() => {
    return props.modelName.split("By")[0].trim();
  });
  const operationCreate = computed(() => {
    if (props.operationCreate) {
      if (typeof props.operationCreate === "string") {
        if (graphqlOperation[props.operationCreate]) return graphqlOperation[props.operationCreate];
      } else {
        return props.operationCreate;
      }
    }
    return graphqlOperation["create" + capitalizeFirstLetter(computedModelName.value)];
  });
  const operationUpdate = computed(() => {
    if (props.operationUpdate) {
      if (typeof props.operationUpdate === "string") {
        if (graphqlOperation[props.operationUpdate]) return graphqlOperation[props.operationUpdate];
      } else {
        return props.operationUpdate;
      }
    }
    return graphqlOperation["update" + capitalizeFirstLetter(computedModelName.value)];
  });
  const operationDelete = computed(() => {
    if (props.operationDelete) {
      if (typeof props.operationDelete === "string") {
        if (graphqlOperation[props.operationDelete]) return graphqlOperation[props.operationDelete];
      } else {
        return props.operationDelete;
      }
    }
    return graphqlOperation["delete" + capitalizeFirstLetter(computedModelName.value)];
  });
  const operationRead = computed(() => {
    if (props.operationRead) {
      if (typeof props.operationRead === "string") {
        if (graphqlOperation[props.operationRead]) return graphqlOperation[props.operationRead];
      } else {
        return props.operationRead;
      }
    }
    return graphqlOperation[lowercaseFirstLetter(props.modelName)];
  });
  const operationReadPageable = computed(() => {
    if (props.operationReadPageable) {
      if (typeof props.operationReadPageable === "string") {
        if (graphqlOperation[props.operationReadPageable]) return graphqlOperation[props.operationReadPageable];
      } else {
        return props.operationReadPageable;
      }
    }
    return graphqlOperation[lowercaseFirstLetter(props.modelName) + "Pageable"];
  });
  const operationSearch = computed(() => {
    if (props.operationSearch) {
      if (typeof props.operationSearch === "string") {
        if (graphqlOperation[props.operationSearch]) return graphqlOperation[props.operationSearch];
      } else {
        return props.operationSearch;
      }
    }
    return graphqlOperation["search" + capitalizeFirstLetter(computedModelName.value)];
  });
  return { operationCreate, operationUpdate, operationDelete, operationRead, operationReadPageable, operationSearch };
}
