import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-ZBWL72TB.js";

// src/hooks/api/sellers.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var SELLERS_QUERY_KEY = "sellers";
var sellersQueryKeys = queryKeysFactory(SELLERS_QUERY_KEY);
var SELLER_MEMBERS_QUERY_KEY = "seller_members";
var sellerMembersQueryKeys = queryKeysFactory(SELLER_MEMBERS_QUERY_KEY);
var SELLER_INVITES_QUERY_KEY = "seller_invites";
var sellerInvitesQueryKeys = queryKeysFactory(SELLER_INVITES_QUERY_KEY);
var useSeller = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.sellers.$id.query({ $id: id, ...query }),
    queryKey: sellersQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var useSellers = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.sellers.query({
      ...query
    }),
    queryKey: sellersQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useSellerProducts = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.sellers.$id.products.query({ $id: id, ...query }),
    queryKey: [...sellersQueryKeys.detail(id), "products", query],
    ...options
  });
  return { ...data, ...rest };
};
var useCreateSeller = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.sellers.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: sellersQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useSuspendSeller = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.sellers.$id.suspend.mutate({ $id: id, reason: payload?.reason }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useApproveSeller = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.sellers.$id.approve.mutate({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateSeller = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.sellers.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateSellerAddress = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.sellers.$id.address.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateSellerPaymentDetails = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.sellers.$id.paymentDetails.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateSellerProfessionalDetails = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.sellers.$id.professionalDetails.mutate({
      $id: id,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: sellersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useSellerMembers = (sellerId, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.sellers.$id.members.query({ $id: sellerId, ...query }),
    queryKey: sellerMembersQueryKeys.list({ sellerId, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useInviteSellerMember = (sellerId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.sellers.$id.members.invite.mutate({
      $id: sellerId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellerMembersQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: sellerInvitesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddSellerMember = (sellerId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.sellers.$id.members.mutate({
      $id: sellerId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellerMembersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveSellerMember = (sellerId, memberId, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.sellers.$id.members.$memberId.delete({
      $id: sellerId,
      $memberId: memberId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellerMembersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteSellerInvite = (sellerId, options) => {
  return useMutation({
    mutationFn: ({ invite_id }) => sdk.admin.sellers.$id.members.invites.$inviteId.delete({
      $id: sellerId,
      $inviteId: invite_id
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellerInvitesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useResendSellerInvite = (sellerId, options) => {
  return useMutation({
    mutationFn: ({ invite_id }) => sdk.admin.sellers.$id.members.invites.$inviteId.resend.mutate({
      $id: sellerId,
      $inviteId: invite_id
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: sellerInvitesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useSellerInvites = (sellerId, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.sellers.$id.members.invites.query({
      $id: sellerId,
      ...query
    }),
    queryKey: sellerInvitesQueryKeys.list({ sellerId, ...query }),
    ...options
  });
  return { ...data, ...rest };
};

export {
  sellersQueryKeys,
  useSeller,
  useSellers,
  useSellerProducts,
  useCreateSeller,
  useSuspendSeller,
  useApproveSeller,
  useUpdateSeller,
  useUpdateSellerAddress,
  useUpdateSellerPaymentDetails,
  useUpdateSellerProfessionalDetails,
  useSellerMembers,
  useInviteSellerMember,
  useAddSellerMember,
  useRemoveSellerMember,
  useDeleteSellerInvite,
  useResendSellerInvite,
  useSellerInvites
};
