import request from '@/utils/request';

// 新增政策法规
export async function addPolicy(data: API.PolicyRequest): Promise<API.Response<string>> {
  return request('/portals/regulations', {
    method: 'POST',
    data,
  });
}

// 更新政策法规
export async function updatePolicy(id: string, data: API.PolicyRequest): Promise<API.Response<string>> {
  return request(`/portals/regulations`, {
    method: 'PUT',
    data: {
      ...data,
      id,
    },
  });
}

// 获取政策法规列表
export async function getPolicyList(params: Partial<API.PolicyRequest>): Promise<API.Response<API.PolicyRecord[]>> {
  return request('/portals/regulations', {
    method: 'GET',
    params,
  });
}

// 获取政策法规分页列表
export async function getPolicyPage(params: API.PageRequest): Promise<API.Response<API.PageResponse<API.PolicyRecord>>> {
  return request('/portals/regulations/getPage', {
    method: 'POST',
    data: params,
  });
}

// 获取政策法规详情
export async function getPolicyDetail(id: string): Promise<API.Response<API.PolicyRecord>> {
  return request(`/portals/regulations/${id}`, {
    method: 'GET',
  });
}

// 删除政策法规
export async function deletePolicy(id: string): Promise<API.Response<string>> {
  return request(`/portals/regulations/${id}`, {
    method: 'DELETE',
  });
}

// 发布(上架)政策法规
export async function publishPolicy(id: string): Promise<API.Response<string>> {
  return request(`/portals/regulations/up/${id}`, {
    method: 'POST',
  });
}

// 下架政策法规
export async function unpublishPolicy(id: string): Promise<API.Response<string>> {
  return request(`/portals/regulations/down/${id}`, {
    method: 'POST',
  });
}
