
import request from '@/config/axios'

export interface jobVO {
  id: number,
  ticketCode: string,
  ticketName: string,
  workshopId: number,
  workstationId: number,
  machineryId: number,
  sopId: number,
  ticketType: number,
  ticketContent: string,
  ticketStatus: number,
  ticketStartTime: string,
  ticketEndTime: string,
  remark: string,
}

export interface PageParam {
  pageNo: number
  pageSize: number
  ticketName?: string
  ticketType?: string
  machineryId?: string
  sopId?: number,
  workstationId: number,
}

// 查询Job列表
export const getJobTicketPage = async (params: PageParam) => {
  return await request.get({ url: '/iscs/job-ticket/getJobTicketPage', params })
}
// 自动生成名称
export const autoGenerateName = async (name) => {
  return await request.get({
    url: '/iscs/job-ticket/autoGenerateName',
    params: { name }  // ✅ 这里 axios 会自动 encodeURIComponent
  })
}


// 获取Job详细信息
export const selectJobTicketById = async (id: number) => {
  return await request.get({ url: '/iscs/job-ticket/selectJobTicketById', params: { id: id } })
}


// 新增Job 不通过sop创建
export const insertJobTicket = async (data: jobVO) => {
  return await request.post({ url: '/iscs/job-ticket/insertJobTicket', data })
}
// 新增Job 通过sop创建
export const insertJobTicketBySop = async (data: jobVO) => {
  return await request.post({ url: '/iscs/job-ticket/insertJobTicketBySop', data })
}
// 修改Job
export const updateJobTicket = async (data: jobVO) => {
  return await request.put({ url: '/iscs/job-ticket/updateJobTicket', data })
}

// 删除Job
export const deleteJobTicketList = async (ids: number) => {
  return await request.delete({
    url: '/iscs/job-ticket/deleteJobTicketList?ids='+ids,
  })
}

//获得作业日志
export const getTicketOperLogPage = async (data)=>{
  return await request.get({url:'/iscs/ticket-oper-log/getTicketOperLogPage', params: data })
}
