import { createRequest } from '@/utils/request'
import type { ResponseStructure } from '@/utils/request'

// ==================== 类型定义 ====================

/** 图片资源 */
export interface ApiImage {
  preview_url: string
  file_name: string
  id: number
}

/** 轮播图项 */
export interface CarouselItem {
  id: number
  title: string
  image: ApiImage
  link: string
  status: number // 0: 启用
  sort: number
}

/** 宫格导航项 */
export interface GridNavItem {
  id: number
  title: string
  image: ApiImage
  link: string
  status: number // 0: 启用
  sort: number
}

/** 首页数据 */
export interface HomeData {
  carousel: CarouselItem[]
  gridNav: GridNavItem[]
}

// ==================== API ====================

/**
 * 获取首页数据（无需登录）
 */
export async function getHomeData(): Promise<ResponseStructure<HomeData>> {
  return createRequest<HomeData>({
    url: '/api/home',
    method: 'GET',
  })
}
