import { api } from "@/lib/api-client";
import type { Facility, Asset, FacilityCreateRequest, AssetCreateRequest } from "@/types/facility";
import type { PaginatedResponse, PaginationParams, ApiSuccessResponse } from "@/types";

export const facilityService = {
  async listFacilities(params?: PaginationParams): Promise<PaginatedResponse<Facility>> {
    return api.get<PaginatedResponse<Facility>>("/facilities", params as Record<string, string | number | boolean | undefined>);
  },

  async createFacility(data: FacilityCreateRequest): Promise<Facility> {
    return api.post<Facility>("/facilities", data);
  },

  async updateFacility(id: number, data: Partial<FacilityCreateRequest>): Promise<Facility> {
    return api.patch<Facility>(`/facilities/${id}`, data);
  },

  async deleteFacility(id: number): Promise<ApiSuccessResponse> {
    return api.delete<ApiSuccessResponse>(`/facilities/${id}`);
  },

  async listAssets(params?: PaginationParams): Promise<PaginatedResponse<Asset>> {
    return api.get<PaginatedResponse<Asset>>("/assets", params as Record<string, string | number | boolean | undefined>);
  },

  async createAsset(data: AssetCreateRequest): Promise<Asset> {
    return api.post<Asset>("/assets", data);
  },

  async deleteAsset(id: number): Promise<ApiSuccessResponse> {
    return api.delete<ApiSuccessResponse>(`/assets/${id}`);
  },
};
