// File: lib/services/contract-drawing.service.ts
import apiClient from '@/lib/api/client';
import {
  CreateContractDrawingDto,
  UpdateContractDrawingDto,
  SearchContractDrawingDto,
} from '@/types/dto/drawing/contract-drawing.dto';

export const contractDrawingService = {
  getAll: async (params: SearchContractDrawingDto) => {
    // GET /drawings/contract?projectId=1&page=1...
    const response = await apiClient.get('/drawings/contract', { params });
    // The interceptor returns { statusCode, message, data, meta }
    return response.data;
  },

  /**
   * ดึงรายละเอียดตาม ID
   */
  getByUuid: async (uuid: string) => {
    const response = await apiClient.get(`/drawings/contract/${uuid}`);
    return response.data;
  },

  /**
   * สร้างแบบสัญญาใหม่
   */
  create: async (data: CreateContractDrawingDto | FormData) => {
    const response = await apiClient.post('/drawings/contract', data);
    return response.data;
  },

  /**
   * แก้ไขข้อมูลแบบสัญญา
   */
  update: async (uuid: string, data: UpdateContractDrawingDto) => {
    const response = await apiClient.put(`/drawings/contract/${uuid}`, data);
    return response.data;
  },

  /**
   * ลบแบบสัญญา (Soft Delete)
   */
  delete: async (uuid: string) => {
    const response = await apiClient.delete(`/drawings/contract/${uuid}`);
    return response.data;
  },
};
