import axios from "axios";

export const http = axios.create({
  baseURL: "/api"
});

http.interceptors.request.use((config) => {
  const token = localStorage.getItem("admin_token");
  if (token) {
    config.headers.Authorization = `Bearer ${token}`;
  }
  return config;
});

export interface PublicCertificate {
  certificate_no: string;
  learner_name: string;
  certificate_name: string;
  project_code: string;
  course_name: string | null;
  stage_name: string | null;
  issue_date: string;
  issuer_name: string;
  status: string;
  pdf_status: string;
  public_token: string | null;
  public_url: string | null;
  download_url: string | null;
  can_download_pdf: boolean;
  disclaimer: string;
}

export interface Captcha {
  captcha_id: string;
  image: string;
}

export interface ProjectCourse {
  id: number;
  code: string;
  name: string;
  default_certificate_name: string;
  default_course_name: string | null;
  default_stage_name: string | null;
  default_issuer_name: string;
  status: string;
  created_at: string;
  updated_at: string;
}

export interface Learner {
  id: number;
  phone: string;
  current_name: string;
  student_no: string | null;
  status: string;
  remark: string | null;
  created_at: string;
  updated_at: string;
}

export interface AdminCertificate {
  id: number;
  learner_id: number;
  project_code: string;
  certificate_no: string;
  certificate_name: string;
  class_name: string | null;
  course_name: string | null;
  stage_name: string | null;
  issue_date: string;
  issuer_name: string;
  status: string;
  pdf_status: string;
  created_at: string;
  updated_at: string;
}

export interface ImportBatch {
  id: number;
  filename: string;
  status: string;
  total_rows: number;
  valid_rows: number;
  failed_rows: number;
  conflict_rows: number;
  error_report_path: string | null;
  created_at: string;
  updated_at: string;
}

export interface OperationLog {
  id: number;
  admin_user_id: number | null;
  action: string;
  action_label: string;
  object_type: string;
  object_label: string;
  object_id: string | null;
  ip_address: string | null;
  detail_json: string | null;
  risk: string;
  risk_label: string;
  summary: string;
  created_at: string;
}

export interface DatabaseBackup {
  filename: string;
  database_type: string;
  created_at: string;
  size_bytes: number;
  size_label: string;
  reason: string | null;
  note: string | null;
}

export interface RestoreDatabaseBackupResult {
  restored_backup: DatabaseBackup;
  pre_restore_backup: DatabaseBackup;
}

export interface PdfSettings {
  pdf_generation_concurrency_limit: number;
  updated_at: string | null;
}
