import { apiClient } from './client'
import type { TenantResponse, TenantCreateRequest, TenantUpdateRequest } from '@/types/api.types'

export const tenantsApi = {
  list(): Promise<TenantResponse[]> {
    return apiClient.get<TenantResponse[]>('/tenants').then((r) => r.data)
  },

  get(id: string): Promise<TenantResponse> {
    return apiClient.get<TenantResponse>(`/tenants/${id}`).then((r) => r.data)
  },

  create(data: TenantCreateRequest): Promise<TenantResponse> {
    return apiClient.post<TenantResponse>('/tenants', data).then((r) => r.data)
  },

  update(id: string, data: TenantUpdateRequest): Promise<TenantResponse> {
    return apiClient.patch<TenantResponse>(`/tenants/${id}`, data).then((r) => r.data)
  },

  suspend(id: string): Promise<TenantResponse> {
    return apiClient.patch<TenantResponse>(`/tenants/${id}`, { is_active: false }).then((r) => r.data)
  },

  activate(id: string): Promise<TenantResponse> {
    return apiClient.patch<TenantResponse>(`/tenants/${id}`, { is_active: true }).then((r) => r.data)
  },
}
