import { request } from 'umi';
import { api } from '../api';
// =============================================== 广点通===============================================
/**广点通账号列表*/
export interface gdtAccountProps {
  userId: string,
  pageNum: number,
  pageSize: number,
  accountIds?: string,
  putResourceId?: number
}
export async function getGdtAccountApi(params: gdtAccountProps) {
  let { userId, pageNum, pageSize, accountIds, putResourceId } = params
  return request(api + `/erp/gdtAccount/list/${userId}`, {
    method: 'POST',
    data: { pageNum, pageSize, accountIds, putResourceId }
  });
}

/** 变更记录 */
export async function getGdtChangeRecordApi(params: { gdtAccountId: number, pageNum: number, pageSize: number }) {
  let { gdtAccountId, ...param } = params
  return request(api + `/adq/adAccount/sysChangeRecord/${gdtAccountId}`, {
    method: 'POST',
    data: param
  });
}

/** 变更记录修改 */
export async function editGdtChangeRecordApi(params: { recordId: number, putResourceId: number, beginTime: string, endTime: string }) {
  let { recordId, ...param } = params
  return request(api + `/adq/adAccount/sysChangeRecordModify/${recordId}`, {
    method: 'PUT',
    data: param
  });
}

/**批量新增广点通账号*/
export interface addGdtAccointProps {
  userId: string,
  accountIds: string,
  putResourceId: number,
  beginTime: string
}
export async function addGdtAccountApi(params: addGdtAccointProps) {
  let { userId, ...param } = params
  return request(api + `/erp/gdtAccount/addBatch/${userId}`, {
    method: 'POST',
    data: param
  });
}
/**编辑广点通账号 */
export interface editGdtAccountProps {
  accountId: string,
  gdtAccountId: string,
  putResourceId: number,
  beginTime: string
}
export async function editGdtAccountApi(params: editGdtAccountProps) {
  let { gdtAccountId, ...param } = params
  return request(api + `/erp/gdtAccount/${gdtAccountId}`, {
    method: 'PUT',
    data: param,
  });
}
/**广点通账号-批量切号*/
export interface checkGdtAccountProps {
  gdtAccountIds: string,
  putResourceId: number,
  beginTime: string
}
export async function checkGdtAccountGdtApi(params: { gdtAccountIds: string, putResourceId: any, beginTime: any }) {
  let { gdtAccountIds, ...param } = params
  return request(api + `/adq/adAccount/checkBatch/${gdtAccountIds}`, {
    method: 'PUT',
    data: param,
  });
}
/**广点通账号-批量删除*/
export async function delGdtAccountApi(params: { gdtAccountIds: string }) {
  let { gdtAccountIds } = params
  return request(api + `/erp/gdtAccount/${gdtAccountIds}`, {
    method: 'DELETE',
  });
}
// =============================================== 应用宝===============================================
/**快应用账号列表*/
export interface QuickAppAccout {
  userId: string;
  pageNum: number,
  pageSize: number,
  advertiserIds?: string,
  account?: string,
  putResourceId?: number
}
export async function getQuickAppAccountApi(params: QuickAppAccout) {
  let { userId, ...param } = params
  return request(api + `/erp/quickAppAccount/list/${userId} `, {
    method: 'POST',
    data: param
  });
}
/**变更记录 */
export async function getAccountChangeRecordApi(params: { quickAppAccountId: number, pageNum: number, pageSize: number }) {
  let { quickAppAccountId, ...param } = params
  return request(api + `/erp/quickAppAccount/accountChangeRecord/${quickAppAccountId}`, {
    method: 'POST',
    data: param
  });
}

/** 变更记录修改 */
export async function editAccountChangeRecordApi(params: { recordId: number, putResourceId: number, beginTime: string, endTime: string }) {
  let { recordId, ...param } = params
  return request(api + `/erp/quickAppAccount/accountChangeRecordModify/${recordId}`, {
    method: 'PUT',
    data: param
  });
}

/**批量新增块应用账号*/
export interface AddQuickAppAccount {
  userId: string,
  advertiserIds: string, // 账号ID
  accountName: string, // 总账号名称
  account: string,   // 总账号
  accountPassword: string, // 总账号密码
  putResourceId: number,
  beginTime: string
}
export async function addQuickAppAccountApi(params: AddQuickAppAccount) {
  let { userId, ...param } = params
  return request(api + `/erp/quickAppAccount/addBatch/${userId}`, {
    method: 'POST',
    data: param
  });
}
/**编辑块应用账号 */
export interface EditQuickAppAccount {
  accountId: string,
  advertiserId: string,
  accountName: string,
  account: string,
  accountPassword: string,
  putResourceId: number,
  beginTime: string
}
export async function editQuickAppAccountApi(params: EditQuickAppAccount) {
  let { accountId, ...param } = params
  return request(api + `/erp/quickAppAccount/${accountId}`, {
    method: 'PUT',
    data: param,
  });
}
/**块应用账号-批量切号*/
export interface CheckQuickAppAccount {
  quickAppAccountIds: string,
  putResourceId: number,
  beginTime: string
}
export async function checkQuickAppAccountApi(params: CheckQuickAppAccount) {
  let { quickAppAccountIds, ...param } = params
  return request(api + `/erp/quickAppAccount/checkBatch/${quickAppAccountIds}`, {
    method: 'PUT',
    data: param,
  });
}
/**块应用账号-批量删除*/
export async function delQuickAppAccountApi(params: { quickAppAccountIds: string }) {
  let { quickAppAccountIds } = params
  return request(api + `/erp/quickAppAccount/${quickAppAccountIds}`, {
    method: 'DELETE',
  });
}


// =============================================== 公用===============================================
/**0-公众号，10：快应用包*/
export async function queryApi(params: { resourceType: string; resourceName: string }) {
  let { resourceType, resourceName } = params
  return request(api + `/erp/resource/query/10,0,3,20,1,4,5,30/${resourceName || 'null'}`);
  // return request(api + `/erp/resource/query/${resourceType}/${resourceName || 'null'}`);
}


// ============================================ 快应用包管理 =========================================
/** 获取快应用包列表 */
export interface KyyListProps {
  userId: string;
  pageNum: number,
  pageSize: number,
  resourceType: 10,
  resourceName?: string,
  periodId?: number
}
export async function getKyyListApi(params: KyyListProps) {
  return request(api + `/erp/resourceOfUser/list`, { method: 'POST', data: params });
}

/**
 * 获取投放信息
 * @param userId 用户ID
 * @param resourceType 资源类型
 * @returns 
 */
export async function getResourceOfUserApi({ userId, resourceType }: { userId: number, resourceType: 10 | 0 }) {
  return request(`${api}/erp/resourceOfUser/${userId}/${resourceType}`)
}


// 指派
export async function cutPutApi({ accountIds, putUserId }: { accountIds: number, putUserId: number }) {
  return request(`${api}/adq/adAccount/configPutUser/${accountIds}/${putUserId}`, {
    method: 'PUT'
  })
}

/**
 * 指派投放助理
 * @param data 
 * @returns 
 */
export async function addAccountUserApi(data: { accountIds: number[], putUserIds: number }) {
  return request(`${api}/adq/adAccount/modifyAccountUser`, {
    method: 'POST',
    data
  })
}