import request from '@/utils/request'
import { queryLikeFieldMethod, queryLikeFieldMethod2 } from '@/utils/queryFieldMethod'
import type { NewsData } from '@/api/home'

enum API {
  SEARCH_URL = '/crmBusinessLicenseInformation/findByPage',
  NEWS_URL = '/crmNewsRelease/findByPage',
}

export interface SearchDataResult {
  countId: number,
  current: number,
  maxLimit: any,
  optimizeCountSql: boolean,
  orders: any,
  pages: number,
  records:SearchDataList,
  searchCount: boolean,
  size: number,
  total:number
}
export interface SearchData {
  address: string;
  approvalTime: string;
  businessPeriod: string;
  businessScope: string;
  cancellationTime: string;
  contactName: string;
  contactPhone: string;
  enterpriseName: string;
  enterprisePhone: string;
  enterpriseType: string;
  establishmentDate: string;
  id: number;
  industryCode: string;
  legalRepresentative: string;
  legalRepresentativeId: string;
  paidInCapital: string;
  postalCode: string;
  registerNumber: string;
  registeredCapital: string;
  registrationAuthority: string;
  registrationCategory: string;
  status: string;
  supervisoryAuthority: string;
  unifiedSocialCreditCode: string;
}
export interface NewsDataResult {
  countId: number,
  current: number,
  maxLimit: any,
  optimizeCountSql: boolean,
  orders: any,
  pages: number,
  records:SearchDataList,
  searchCount: boolean,
  size: number,
  total:number
}

export type SearchDataList = NewsData[];

export const getSearchDataResult = (pageNum:number,pageSize:number,searchModule:string,searchValue:string)=>{
  if(searchModule == '0'){
    return request<any,SearchDataResult>({
      url:API.SEARCH_URL,
      method:'get',
      params:queryLikeFieldMethod('enterprise_name',searchValue,pageNum,pageSize)
    });
  }else if(searchModule == '1'){
    return request<any,SearchDataResult>({
      url:API.SEARCH_URL,
      method:'get',
      params:queryLikeFieldMethod('unified_social_credit_code',searchValue,pageNum,pageSize)
    });
  }else if(searchModule == '2'){
    return request<any,NewsDataResult>({
      url:API.NEWS_URL,
      method:'get',
      params:queryLikeFieldMethod('title',searchValue,pageNum,pageSize)
    });
  }else {
    // return request<any,SearchDataResult>({
    //   url:API.SEARCH_URL,
    //   method:'get',
    //   params:queryLikeFieldMethod('enterpriseName',searchValue,pageNum,pageSize)
    // });
  }
  console.log(searchValue)
}