import type { UserInfo } from '@vben/types';

import { requestClient } from '#/api/request';

export namespace UserApi {
  export interface ApplicationFilter {
    name: string;
    value: boolean | number | string;
  }

  export interface GetMyApplicationListParams {
    currentPage: number;
    pageSize: number;
    orderByProperty?: string;
    Ascending?: boolean;
    totalPage?: number;
    totalCount?: number;
    filters?: ApplicationFilter[];
  }

  export interface ApplicationModel {
    cellPhone: string;
    client_code: string;
    client_name: string;
    code: string;
    contact: string;
    from_code: string;
    from_name: string;
    id: string;
    imgPhotoFileId: string;
    isEnable: boolean;
    isOwner: boolean;
    isReleased: boolean;
    langName: string;
    language: string;
    name: string;
    memo?: string;
    number0fBusinessScenarios: number;
    number0fCSiteMaxUser: number;
    number0fDesigners: number;
    number0fPages: number;
    number0fTables: number;
    number0fWorkFlow: number;
    usedBusinessScenarios: number;
    usedCSiteMaxUser: number;
    usedDesigners: number;
    usedPages: number;
    usedTables: number;
    usedWorkFlow: number;
    webSite: string;
    web_build_status: number;
  }

  export interface GetMyApplicationListResult {
    result: any;
    currentPage: number;
    hasNextPage: boolean;
    hasPreviousPage: boolean;
    model: ApplicationModel[];
    pageSize: number;
    totalCount: number;
    totalPages: number;
  }

  export interface DeliveryPartnerFilter {
    name: string;
    value?: boolean | number | string;
  }

  export interface GetDeliveryPartnersParams {
    currentPage: number;
    pageSize: number;
    orderByProperty?: string;
    Ascending?: boolean;
    totalPage?: number;
    totalCount?: number;
    filters?: DeliveryPartnerFilter[];
  }

  export interface DeliveryPartnerModel {
    account: string;
    id: string;
    langName: string;
    name: string;
    expiredTime?: string;
    number0fBusinessScenarios: number;
    number0fCSiteMaxUser: number;
    number0fDesigners: number;
    number0fEnterprise: number;
    number0fPages: number;
    number0fTables: number;
    number0fWorkFlow: number;
    status: boolean;
    usedBusinessScenarios: number;
    usedCSiteMaxUser: number;
    usedDesigners: number;
    usedEnterprise: number;
    usedPages: number;
    usedTables: number;
    usedWorkFlow: number;
  }

  export interface LangName {
    name: string;
    value: string;
  }

  export interface AddApplicationParams {
    isEnable: boolean;
    langNameList: LangName[];
    fileId?: string;
    imgPhotoFileId?: string;
    version?: string;
    partnerInfoId?: string;
    code?: string;
    from_code?: string;
    number0fWorkFlow?: number;
    usedWorkFlow?: number;
    usedPages?: number;
    number0fPages?: number;
    usedTables?: number;
    number0fTables?: number;
    usedDesigners?: number;
    number0fDesigners?: number;
    number0fBusinessScenarios?: number;
    usedBusinessScenarios?: number;
    usedCSiteMaxUser?: number;
    number0fCSiteMaxUser?: number;
    langName?: null | string;
    contact?: string;
    phone?: string;
    email?: string;
    address?: string;
    description?: string;
    customerRelation?: string;
    nameCn?: string;
    nameEn?: string;
    cloneProject?: string;
    projectCode?: string;
    partner?: string;
  }

  export interface AddApplicationResult {
    isSuccess: boolean;
    code: number;
    result: boolean;
    isAuthorized: boolean;
  }

  export interface GetDeliveryPartnersResult {
    result: any;
    currentPage: number;
    hasNextPage: boolean;
    hasPreviousPage: boolean;
    model: DeliveryPartnerModel[];
    pageSize: number;
    totalCount: number;
    totalPages: number;
  }
}

/**
 * 获取用户信息
 */
export async function fetchUserInfoApi() {
  return requestClient.get<UserInfo>('/user/info');
}

/**
 * 获取我的应用列表
 */
export async function getMyApplicationListApi(
  data: UserApi.GetMyApplicationListParams,
) {
  return requestClient.post<UserApi.GetMyApplicationListResult>(
    '/api/enterprise/myList',
    data,
  );
}

/**
 * 获取交付伙伴
 */
export async function getDeliveryPartnersApi(
  data: UserApi.GetDeliveryPartnersParams,
) {
  return requestClient.post<UserApi.GetDeliveryPartnersResult>(
    '/api/user/list',
    data,
  );
}

/**
 * 获取合作伙伴
 */
export async function getPartnersApi() {
  return requestClient.post('api/partner/AllList');
}

/**
 * 获取可以克隆的项目
 */
export async function getCloneApplicationsApi(
  data: UserApi.GetDeliveryPartnersParams,
) {
  return requestClient.post('/api/enterprise/myList', data);
}

/**
 * 添加应用
 */
export async function addApplicationApi(data: UserApi.AddApplicationParams) {
  return requestClient.post<UserApi.AddApplicationResult>(
    '/api/enterprise/doCreate',
    data,
  );
}

/**
 * 添加 删除应用
 */
export async function deleteApplicationApi(data: { id: string }) {
  return requestClient.post<UserApi.AddApplicationResult>(
    '/api/enterprise/doDelete',
    data,
  );
}
