const { contextBridge, ipcRenderer } = require('electron');
const fs = require('fs');
const path = require('path');
const os = require('os');

contextBridge.exposeInMainWorld('electronAPI', {
  minimize: () => ipcRenderer.send('window-minimize'),
  maximize: () => ipcRenderer.send('window-maximize'),
  close: () => ipcRenderer.send('window-close'),

  readMessageFile: () => {
    const filePath = path.join(__dirname, 'message.txt');
    try {
      const content = fs.readFileSync(filePath, 'utf8');
      return content;
    } catch {
      return null;
    }
  },

  getUserDataPath: () => {
    return path.join(os.homedir(), 'AppData', 'Roaming', 'ぶぅたんのねごと');
  },

  saveFile: (filePath, content) => {
    fs.writeFileSync(filePath, content, 'utf8');
  },

  readJsonFile: (filePath) => {
    try {
      return JSON.parse(fs.readFileSync(filePath, 'utf8'));
    } catch {
      return null;
    }
  }
});