import { useContentGqlHandler } from "./useContentGqlHandler" ; import { GQLHandlerCallableParams } from "./useGqlHandler" ; const categoryFields = `
    id
    entryId
    createdOn
    createdBy {
        id
        displayName
        type
    }
    savedOn
    meta {
        title
        modelId
        version
        locked
        publishedOn
        status
        revisions {
            id
            title
            slug
            meta {
                status
                version
            }
        }
    }
    # user defined fields
    title
    slug
` ; const errorFields = `
    error {
        code
        message
        data
    }
` ; const getCategoryQuery = `
    query GetCategory($revision: ID!) {
        getCategory(revision: $revision) {
            data {
                ${ categoryFields }
            }
            ${ errorFields }
        }
    }
` ; const getCategoriesByIdsQuery = `
    query GetCategories($revisions: [ID!]!) {
        getCategoriesByIds(revisions: $revisions) {
            data {
                ${ categoryFields }
            }
            ${ errorFields }
        }
    }
` ; const listCategoriesQuery = `
    query ListCategories(
        $where: CategoryListWhereInput
        $sort: [CategoryListSorter]
        $limit: Int
        $after: String
    ) {
        listCategories(where: $where, sort: $sort, limit: $limit, after: $after) {
            data {
                ${ categoryFields }
            }
            meta {
                cursor
                hasMoreItems
                totalCount
            }
            ${ errorFields }
        }
    }
` ; const createCategoryMutation = `
    mutation CreateCategory($data: CategoryInput!) {
        createCategory(data: $data) {
            data {
                ${ categoryFields }
            }
            ${ errorFields }
        }
    }
` ; const createCategoryFromMutation = `
    mutation CreateCategoryFrom($revision: ID!) {
        createCategoryFrom(revision: $revision) {
            data {
                ${ categoryFields }
            }
            ${ errorFields }
        }
    }
` ; const updateCategoryMutation = `
    mutation UpdateCategory($revision: ID!, $data: CategoryInput!) {
        updateCategory(revision: $revision, data: $data) {
            data {
                ${ categoryFields }
            }
            ${ errorFields }
        }
    }
` ; const deleteCategoryMutation = `
    mutation DeleteCategory($revision: ID!) {
        deleteCategory(revision: $revision) {
            data
            ${ errorFields }
        }
    }
` ; const publishCategoryMutation = `
    mutation PublishCategory($revision: ID!) {
        publishCategory(revision: $revision) {
            data {
                ${ categoryFields }
            }
            ${ errorFields }
        }
    }
` ; const republishCategoryMutation = `
    mutation RepublishCategory($revision: ID!) {
        republishCategory(revision: $revision) {
            data {
                ${ categoryFields }
            }
            ${ errorFields }
        }
    }
` ; const unpublishCategoryMutation = `
    mutation UnpublishCategory($revision: ID!) {
        unpublishCategory(revision: $revision) {
            data {
                ${ categoryFields }
            }
            ${ errorFields }
        }
    }
` ; const requestCategoryChangesMutation = `
    mutation RequestCategoryChanges($revision: ID!) {
        requestCategoryChanges(revision: $revision) {
            data {
                ${ categoryFields }
            }
            ${ errorFields }
        }
    }
` ; const requestCategoryReviewMutation = `
    mutation RequestCategoryReview($revision: ID!) {
        requestCategoryReview(revision: $revision) {
            data {
                ${ categoryFields }
            }
            ${ errorFields }
        }
    }
` ; export const useCategoryManageHandler = ( params ) => { const contentHandler = useContentGqlHandler ( params ) ; return { ... contentHandler , async getCategory ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : getCategoryQuery , variables } , headers } ) ; } , async getCategoriesByIds ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : getCategoriesByIdsQuery , variables } , headers } ) ; } , async listCategories ( variables = { } , headers = { } ) { return await contentHandler . invoke ( { body : { query : listCategoriesQuery , variables } , headers } ) ; } , async createCategory ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : createCategoryMutation , variables } , headers } ) ; } , async createCategoryFrom ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : createCategoryFromMutation , variables } , headers } ) ; } , async updateCategory ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : updateCategoryMutation , variables } , headers } ) ; } , async deleteCategory ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : deleteCategoryMutation , variables } , headers } ) ; } , async publishCategory ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : publishCategoryMutation , variables } , headers } ) ; } , async republishCategory ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : republishCategoryMutation , variables } , headers } ) ; } , async unpublishCategory ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : unpublishCategoryMutation , variables } , headers } ) ; } , async requestCategoryChanges ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : requestCategoryChangesMutation , variables } , headers } ) ; } , async requestCategoryReview ( variables , headers = { } ) { return await contentHandler . invoke ( { body : { query : requestCategoryReviewMutation , variables } , headers } ) ; } } ; } ;