import { http } from '../../../server'
import {
    ItaskIdParams,
    IjoinInParams,
    IjoinInEmailParams,
    IloginThirdParam,
    IgetTaskParams,
    IsaveTaskParams,
    IrunTaskParams,
    IsendVerificationCodeParams,
    IsendEmailVerificationCodeParams,
    IgetMaskDataParams,
    IgetSegementParams,
    IgetImage2KParams,
    InoLoginParams,
    IFreshParams,
    IgetinvitationCodeParams,
    IgetinvitationRecordParams,
    IcheckSmsCodeParams,
    IsmsLoginParams,
    IsmsSignupParams,
    IgetinvitationUsersParams,
    IreplicableExecutionsParams,
    IexecutionFaceDetectParams,
    IrenameTaskParams,
    IstartImageParams,
    IgetBodySegmentParams,
    // IgetPromptSuggestionParams,
} from './type'
import { AxiosRequestHeaders, InternalAxiosRequestConfig } from 'axios'

// 获取模板
export const getTemplate = (data: { agentName: string | null; agentVersion?: string }) => {
    return http.get('/v1/agent/info/locations', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

// 获取任务状态
export const getTaskStatus = (data: ItaskIdParams) => {
    return http.get('/taskStatus', { params: data, headers: {} as AxiosRequestHeaders })
}

// 申请加入
export const joinIn = (data: IjoinInParams) => {
    return http.post('/login', data)
}

// 申请加入
export const joinInEmail = (data: IjoinInEmailParams) => {
    return http.post('/emailLogin', data)
}

// 三方登录
export const loginThird = (data: IloginThirdParam) => {
    return http.post('/thirdPartyLogin', data)
}

// 验证码检验
export const checkSmsCode = (data: IcheckSmsCodeParams) => {
    return http.post('/checkSmsCode', data)
}

// 老用户登录
export const smsLogin = (data: IsmsLoginParams) => {
    return http.post('/smsLogin', data)
}

// 新用户登录
export const smsSignup = (data: IsmsSignupParams) => {
    return http.post('/smsSignup', data)
}

//新老用户检测
export const isFresh = (data: IFreshParams) => {
    return http.post('/isFresh', data)
}

// 登出
export const joinOut = () => {
    return http.post('/logout')
}

//发送登录验证码
export const sendVerificationCode = (data: IsendVerificationCodeParams) => {
    return http.post('/smsCode', data)
}

//发送登录邮箱验证码
export const sendEmailVerificationCode = (data: IsendEmailVerificationCodeParams) => {
    return http.post('/emailCode', data)
}

export const emailLogin = (data: { email: string; code: string; inviterId?: string }) => {
    return http.post('/emailLogin', data)
}

//查询用户信息
export const getUser = (data: InoLoginParams) => {
    return http.get('/user', { params: data, headers: {} as AxiosRequestHeaders })
}

// 获取模特(新版)
export const getModel = (data: { agentName: string | null; agentVersion?: string }) => {
    return http.get('/v1/agent/info/fashionModels', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}
// 获取任务列表
export const getTask = (data: IgetTaskParams) => {
    return http.post('/v1/agent/task/list', data)
}

// 获取tag列表
export const getTags = (data: { agentName: string | null; agentVersion?: string | null }) => {
    return http.get('/v1/agent/info/tags', { params: data, headers: {} as AxiosRequestHeaders })
}

// 创建 or 编辑任务
export const saveTask = (data: IsaveTaskParams) => {
    return http.post(`/v1/agent/task/save?paramType=${data.paramType}`, data)
}

// 重命名
export const renameTask = (data: IrenameTaskParams) => {
    return http.post('/v1/agent/task/rename', data)
}

// 提交任务
export const runTask = (data: IrunTaskParams) => {
    return http.post('/v1/agent/task/execute', data)
}

// 删除任务
export const deleteTask = (data: IrunTaskParams) => {
    return http.post(`/v1/agent/task/delete?taskId=${data.taskId}`)
}

// 获取任务的执行记录
export const replicableExecutions = (data: IreplicableExecutionsParams) => {
    return http.get('/v1/agent/task/replicableExecutions', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

//检测人脸
export const executionFaceDetect = (data: IexecutionFaceDetectParams) => {
    return http.get('/v1/agent/task/executionFaceDetect', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

// 查询未完成的执行记录(轮训用)
export const taskExecutions = (data: IrunTaskParams) => {
    return http.post('/v1/agent/task/executions', data)
}

export const taskExecutionStars = (data: IrunTaskParams) => {
    return http.post('/v1/agent/task/executionStars', data)
}
// 星标打标
export const starImage = (data: IstartImageParams) => {
    return http.post('/v1/agent/starImage', data)
}

// 查询已完成的执行记录
export const taskExecutionList = (data: IrunTaskParams) => {
    return http.get('/finishedTaskExecutions', { params: data, headers: {} as AxiosRequestHeaders })
}

// 查询任务详情
export const getTaskDetail = (data: IrunTaskParams) => {
    return http.get('/v1/agent/task/detail', { params: data, headers: {} as AxiosRequestHeaders })
}

export const getMaskData = (data: IgetMaskDataParams) => {
    return http.get('/imgseg-all', { params: data, headers: {} as AxiosRequestHeaders })
}

export const getSegement = (data: IgetSegementParams) => {
    return http.get('/v1/agent/segment', { params: data, headers: {} as AxiosRequestHeaders })
}

// 主体分割
export const getBodySegment = (data: IgetBodySegmentParams) => {
    return http.get('/v1/agent/bodySegment', { params: data, headers: {} as AxiosRequestHeaders })
}

// 更新模型
export const updateSegment = (data: IgetSegementParams) => {
    return http.post('/v1/agent/updateSegment', data)
}

// //下载4k
// export const getImage4K = (data: IgetImage4KParams) => {
//     return http.get('/upscale', { params: data, headers: {} as AxiosRequestHeaders })
// }

// 总收益（钱包信息）
export const getWallet = () => {
    return http.get('/wallet')
}

//创建邀请码
export const getNewInvitationID = () => {
    return http.post('/newInvitationID')
}

// 邀请码列表
export const getInvitationCodeList = (data: IgetinvitationCodeParams) => {
    return http.get('/listInvitationID', { params: data, headers: {} as AxiosRequestHeaders })
}

// 邀请记录列表
export const getInvitationRecordList = (data: IgetinvitationRecordParams) => {
    return http.get('/listInvitationRecord', { params: data, headers: {} as AxiosRequestHeaders })
}

//推广用户明细
export const getInvitationUsersList = (data: IgetinvitationUsersParams) => {
    return http.get('/listInvitedUsers', { params: data, headers: {} as AxiosRequestHeaders })
}

// 申请提现按钮
export const getWithdrawFunds = () => {
    return http.post('/withdrawFunds')
}

export const get2KImage = (data: IgetImage2KParams) => {
    return http.post('/v1/agent/task/upscale2k', data, {
        timeout: 300_000,
    } as InternalAxiosRequestConfig)
}

export const get2KImageStatus = (data: { image: string }) => {
    return http.get('/v1/agent/task/upscale2kStatus', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

export const downloadImgName = (data: {
    taskId: string | null
    id: string
    executionId: string
}) => {
    return http.get('/downloadImgName', { params: data, headers: {} as AxiosRequestHeaders })
}

export const getShowCase = (data: {
    agentName: string
    page: number
    tag: string
    offset: number
}) => {
    return http.get('/v1/agent/listStudioCase', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

export const getShowCaseDetail = (data: { id: string; tag: string }) => {
    return http.get('/v1/agent/studioCaseDetail', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

export const getBadge = (data: { agentName: string }) => {
    return http.get('/v1/agent/badge', { params: data, headers: {} as AxiosRequestHeaders })
}

export const viewRecord = (data: { agentName: string }) => {
    return http.post('/v1/agent/viewRecord', data)
}

export const getControllerParams = (data: { id: string }) => {
    return http.get('/v1/agent/playground/controllerParams', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

export const getControllerModels = (data: { id: string; refresh: boolean }) => {
    return http.get('/v1/agent/playground/controllerModels', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

export const getAdetailerParams = (data: { id: string }) => {
    return http.get('/v1/agent/playground/adetailerParams', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

export const getGroundParams = (data: { agentName: string }) => {
    return http.get('/v1/agent/playground/commonParams', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

export const getHiresFixParams = () => {
    return http.get('/v1/agent/playground/hiresFixParams', { headers: {} as AxiosRequestHeaders })
}

export const getControlnetDetect = (data: { taskId: string; module: string; image: string }) => {
    return http.get('/v1/agent/playground/controlnetDetect', {
        params: data,
        headers: {} as AxiosRequestHeaders,
        timeout: 300000,
    })
}

export const getInterrogate = (data: { taskId: string; image: string }) => {
    return http.get('/v1/agent/playground/interrogate', {
        params: data,
        headers: {} as AxiosRequestHeaders,
        timeout: 300000,
    })
}

// 保存mask
export const saveSAMMask = (data: { mask: string; taskId: string }) => {
    return http.post('/v1/agent/task/saveMask', data)
}

// 投稿
export const showCaseSubmission = (data: { id: string }) => {
    return http.post('/v1/agent/showCaseSubmission', data)
}

// 跳转至该任务
export const starImageToTaskInfo = (data: { id: string }) => {
    return http.get('/v1/agent/starImageToTaskInfo', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

// 获取推荐词
export const promptRecommand = (data: { prefix: string }) => {
    return http.get('/v1/agent/promptRecommand', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

// 获取appkey
export const getApiKey = () => {
    return http.get('/listApiKey')
}

// 删除appkey
export const deleteApiKey = (data: { apiKey: string }) => {
    return http.post('/deleteApiKey', data)
}

// 新建appKey
export const createApiKey = () => {
    return http.post('/generateApiKey')
}

export const shopifyUploadImage = (data: { imgUrl: string; imgName: string }) => {
    return http.post('/shopifyUploadImage', data)
}

// 轮询微信订阅状态
export const getWxServiceAccountSubscribeStatus = (data: { ticket: string }) => {
    return http.get('/getWxServiceAccountSubscribeStatus', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

// 刷新二维码
export const refreshSubscriptionQrCodeForSmsSignUp = (data: { key: string }) => {
    return http.get('/refreshSubscriptionQrCodeForSmsSignUp', {
        params: data,
        headers: {} as AxiosRequestHeaders,
    })
}

// 获取订阅二维码
export const getWxServiceAccountSubscriptionQrCode = () => {
    return http.get('/wxServiceAccount/getSubscriptionQrCode', {
        headers: {} as AxiosRequestHeaders,
    })
}

// 获取本机GPU信息（本地版使用）
export const getGpuInfo = () => {
    return http.get('/gpuInfo', {
        params: { noShowToast: true },
        headers: {} as AxiosRequestHeaders,
    })
}

// 获取是否开启日志
export const getLogInfo = () => {
    return http.get('/logInfo', {
        params: { noShowToast: true },
        headers: {} as AxiosRequestHeaders,
    })
}

// 终止任务
export const suspendTask = (data: { taskId: string }) => {
    return http.post('/v1/agent/task/suspend', data)
}
export const getApiPlans = () => {
    return http.get('/apiPlans ', {
        headers: {} as AxiosRequestHeaders,
    })
}

// 获取ip
export const isKorea = () => {
    return http.get('/geoip/isKR')
}

// 默认版本
export const setDefaultAgentVersion = (data: { agentVersion: string }) => {
    return http.post('/v1/agent/setDefaultAgentVersion', data)
}
