import apiClient from "@/lib/api/client"; // ─── Types ──────────────────────────────────────────────────────────────────── export interface CurrencyRateUser { id: number; name: string; username: string; phone: string; email: string; } /** Raw backend entity (GET responses mirror this shape). */ export interface CurrencyRate { id: number; currencyFrom: string; currencyTo: string; value: number; createdBy: CurrencyRateUser; updatedBy: CurrencyRateUser; createdAt: string; updatedAt: string; } /** LIST RESPONSE: GET /currencies */ export interface CurrencyRateListResponse { count: number; currencies: CurrencyRate[]; } /** LIST PARAMS */ export interface CurrencyRateListParams { page?: number; limit?: number; search?: string; currency_from?: string; currency_to?: string; } /** CREATE / UPDATE PAYLOAD (camelCase, JSON) */ export interface CreateCurrencyRatePayload { currencyFrom: string; currencyTo: string; value: number; } export type UpdateCurrencyRatePayload = CreateCurrencyRatePayload; // ─── API Functions ───────────────────────────────────────────────────────────── export const currencyRatesApi = { getList: async (params: CurrencyRateListParams = {}, signal?: AbortSignal): Promise => { const { page, limit, search, currency_from, currency_to } = params; const { data } = await apiClient.get("/currencies", { params: { page, limit, search: search || undefined, currency_from: currency_from || undefined, currency_to: currency_to || undefined, }, signal, }); return data; }, getById: async (id: number): Promise => { const { data } = await apiClient.get(`/currencies/${id}`); return data; }, create: async (payload: CreateCurrencyRatePayload): Promise => { const { data } = await apiClient.post("/currencies", payload); return data; }, update: async (id: number, payload: UpdateCurrencyRatePayload): Promise => { const { data } = await apiClient.put(`/currencies/${id}`, payload); return data; }, delete: async (id: number): Promise => { await apiClient.delete(`/currencies/${id}`); }, }; // ─── Constants ──────────────────────────────────────────────────────────────── export const CURRENCY_OPTIONS: { value: string; label: string }[] = [ { value: "USD", label: "USD — US Dollar" }, { value: "RUB", label: "RUB — Russian Ruble" }, { value: "TMT", label: "TMT — Turkmen Manat" }, { value: "EUR", label: "EUR — Euro" }, { value: "GBP", label: "GBP — British Pound" }, { value: "CNY", label: "CNY — Chinese Yuan" }, { value: "TRY", label: "TRY — Turkish Lira" }, ];