import { BaseApiService } from '@/services/api/base'; import { httpClient } from '@/services/http/client'; import { BaseApiResponse } from '@/types/api/api-general'; import { Marketing, CreateSalesOrderPayload, UpdateSalesOrderPayload, CreateDeliveryOrderPayload, UpdateDeliveryOrderPayload, } from '@/types/api/marketing/marketing'; /** * 💡 Helper untuk membuat respons dummy * @param data Data yang akan dimasukkan ke dalam body respons */ const createDummyResponse = (data: T): BaseApiResponse => ({ code: 200, status: 'success', message: 'Data retrieved successfully (MOCK)', data: data, }); export class SalesOrderService extends BaseApiService< Marketing, CreateSalesOrderPayload, UpdateSalesOrderPayload > { constructor(basePath: string = '/marketing') { super(basePath); } /** * Approve single marketing data */ async singleApproval( id: number, action: 'APPROVED' | 'REJECTED', notes?: string ): Promise | undefined> { try { const path = `${this.basePath}/approvals`; return await httpClient>(path, { method: 'POST', body: { action: action, approvable_ids: [id], notes: notes || `${action} marketing ${id}`, }, }); } catch (error) { console.error('Error approve marketing:', error); return undefined; } } /** * Bulk approve */ async bulkApprovals( ids: number[], action: 'APPROVED' | 'REJECTED', notes?: string ): Promise | undefined> { try { const path = `${this.basePath}/approvals`; return await httpClient>(path, { method: 'POST', body: { action: action, approvable_ids: ids, notes: notes || `${action} marketing ${ids.join(', ')}`, }, }); } catch (error) { console.error('Error bulk approve marketing:', error); return undefined; } } /** * Delivery */ async delivery( id: number, notes?: string ): Promise | undefined> { try { const path = `${this.basePath}/approvals`; return await httpClient>(path, { method: 'POST', body: { action: 'APPROVED', approvable_ids: [id], notes: notes || `Delivery marketing ${id}`, }, }); } catch (error) { console.error('Error delivery marketing:', error); return undefined; } } } export const SalesOrderApi = new SalesOrderService('/marketing/sales-orders'); export const DeliveryOrderApi = new BaseApiService< Marketing, CreateDeliveryOrderPayload, UpdateDeliveryOrderPayload >('/marketing/delivery-orders'); export const MarketingApi = new BaseApiService( '/marketing' );