import type {Environment, CreateEnvironmentRequest, UpdateEnvironmentRequest, EnvironmentQueryParams} from './types';
import type {Page} from '@/types/base';
import request from "@/utils/request";

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

// 获取环境分页列表
export const getEnvironmentPage = (params: EnvironmentQueryParams) =>
    request.get<Page<Environment>>(`${BASE_URL}/page`, {params});

// 创建环境
export const createEnvironment = (data: CreateEnvironmentRequest) =>
    request.post<Environment>(BASE_URL, data);

// 更新环境
export const updateEnvironment = (data: UpdateEnvironmentRequest) =>
    request.put<Environment>(`${BASE_URL}/${data.id}`, data);

// 删除环境
export const deleteEnvironment = (id: number) =>
    request.delete(`${BASE_URL}/${id}`);

// 获取环境详情
export const getEnvironment = (id: number) => 
    request.get<Environment>(`${BASE_URL}/${id}`);

// 获取所有环境列表
export const getEnvironmentList = () => 
    request.get<Environment[]>(`${BASE_URL}/list`);

// 条件查询环境列表
export const getEnvironmentListByCondition = (params?: EnvironmentQueryParams) =>
    request.get<Environment[]>(`${BASE_URL}/list`, { params });
