import request from '@/utils/request';
import type { CreateApplicationRequest, UpdateApplicationRequest, Application, ApplicationQuery } from './types';
import type { Page } from '@/types/base';
import {DevelopmentLanguageType} from "./types";

const BASE_URL = '/api/v1/applications';

// 创建应用
export const createApplication = (data: CreateApplicationRequest) => 
    request.post<void>(BASE_URL, data);

// 更新应用
export const updateApplication = (data: UpdateApplicationRequest) => 
    request.put<void>(`${BASE_URL}/${data.id}`, data);

// 删除应用
export const deleteApplication = (id: number) => 
    request.delete<void>(`${BASE_URL}/${id}`);

// 获取应用详情
export const getApplication = (id: number) => 
    request.get<Application>(`${BASE_URL}/${id}`);

// 分页查询应用列表
export const getApplicationPage = (params?: ApplicationQuery) =>
    request.get<Page<Application>>(`${BASE_URL}/page`, { params });

// 获取所有应用列表
export const getApplicationList = () => 
    request.get<Application[]>(BASE_URL);

// 条件查询应用列表
export const getApplicationListByCondition = (params?: ApplicationQuery) =>
    request.get<Application[]>(`${BASE_URL}/list`, { params });

export const getDevelopmentLanguages = () =>
    request.get<DevelopmentLanguageType[]>(`${BASE_URL}/development-languages`);
