import { RegisterService } from '../services/registerservice.js';
import { sendError } from '../utils/response.js';
import { GeneralService } from '../share/generalservice.js';

export class RegisterController {
  constructor() {
    this.registerService = new RegisterService();
    this.generalService = new GeneralService();
  }

  async onNavigate(req, res) {
    let idx = -1, result = [];
    try {
      const { organization, request } = req.body;
      const { email, fname, lname, password } = request;
      result = await this.registerService.requestRegistration(organization, email, fname, lname, password);
    } catch (error) {
      idx = 1;
      this.generalService.devhint(1, 'registercontroller.js', 'Jumpout', error.message);
      result = error; // จะถูก Global Handler จัด format
    } finally {
      if (idx === 1) return result;
      return result;
    }
  }
}
