import request from '@/utils/http'

const OVERRIDE_BASE_URL = '/api/admin/v1/dictionary/overrides'

export function getOverrides() {
  return request.get<Api.Dictionary.OverrideConfigDto[]>({
    url: OVERRIDE_BASE_URL
  })
}

export function getOverride(groupCode: string) {
  return request.get<Api.Dictionary.OverrideConfigDto>({
    url: `${OVERRIDE_BASE_URL}/${groupCode}`
  })
}

export function enableOverride(groupCode: string) {
  return request.post<Api.Dictionary.OverrideConfigDto>({
    url: `${OVERRIDE_BASE_URL}/${groupCode}/enable`,
    data: {}
  })
}

export function disableOverride(groupCode: string) {
  return request.post<void>({
    url: `${OVERRIDE_BASE_URL}/${groupCode}/disable`,
    data: {}
  })
}

export function updateHiddenItems(
  groupCode: string,
  hiddenItemIds: Api.Dictionary.DictionaryOverrideHiddenItemsRequest['hiddenItemIds']
) {
  return request.put<Api.Dictionary.OverrideConfigDto>({
    url: `${OVERRIDE_BASE_URL}/${groupCode}/hidden-items`,
    data: { hiddenItemIds }
  })
}

export function updateSortOrder(
  groupCode: string,
  sortOrder: Api.Dictionary.DictionaryOverrideSortOrderRequest['sortOrder']
) {
  return request.put<Api.Dictionary.OverrideConfigDto>({
    url: `${OVERRIDE_BASE_URL}/${groupCode}/sort-order`,
    data: { sortOrder }
  })
}
