import apiClient from '@/infrastructure/api/client';
import { API_ENDPOINTS } from '@/infrastructure/api/endpoints';

export type ContactType = 'WECHAT' | 'QQ';

export interface CustomerServiceContact {
  id: string;
  type: ContactType;
  label: string;
  value: string;
  sortOrder: number;
  isEnabled: boolean;
  createdAt: string;
  updatedAt: string;
}

export interface CreateContactPayload {
  type: ContactType;
  label: string;
  value: string;
  sortOrder: number;
  isEnabled?: boolean;
}

export interface UpdateContactPayload {
  type?: ContactType;
  label?: string;
  value?: string;
  sortOrder?: number;
  isEnabled?: boolean;
}

export const customerServiceContactService = {
  /** 查询所有客服联系方式 */
  async list(): Promise<CustomerServiceContact[]> {
    return apiClient.get(API_ENDPOINTS.CUSTOMER_SERVICE_CONTACTS.LIST);
  },

  /** 新增客服联系方式 */
  async create(data: CreateContactPayload): Promise<CustomerServiceContact> {
    return apiClient.post(API_ENDPOINTS.CUSTOMER_SERVICE_CONTACTS.CREATE, data);
  },

  /** 更新客服联系方式 */
  async update(id: string, data: UpdateContactPayload): Promise<CustomerServiceContact> {
    return apiClient.put(API_ENDPOINTS.CUSTOMER_SERVICE_CONTACTS.UPDATE(id), data);
  },

  /** 删除客服联系方式 */
  async delete(id: string): Promise<void> {
    return apiClient.delete(API_ENDPOINTS.CUSTOMER_SERVICE_CONTACTS.DELETE(id));
  },
};

export default customerServiceContactService;
