const http = require('http');

function testLogin() {
  console.log('Testing school login API...');
  
  const schoolCredentials = {
    email: 'school@test.com',
    password: Buffer.from('school123').toString('base64')
  };
  
  const postData = JSON.stringify(schoolCredentials);
  
  const options = {
    hostname: 'localhost',
    port: 3002,
    path: '/api/auth/school/login',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Content-Length': Buffer.byteLength(postData)
    }
  };
  
  const req = http.request(options, (res) => {
    let data = '';
    
    res.on('data', (chunk) => {
      data += chunk;
    });
    
    res.on('end', () => {
      console.log('Response status:', res.statusCode);
      try {
        const jsonData = JSON.parse(data);
        console.log('Response data:', jsonData);
        
        if (res.statusCode === 200) {
          console.log('✓ Login successful!');
          console.log('User:', jsonData.user);
        } else {
          console.log('✗ Login failed:', jsonData.message);
        }
      } catch (error) {
        console.log('Raw response:', data);
      }
    });
  });
  
  req.on('error', (error) => {
    console.error('Request error:', error.message);
  });
  
  req.write(postData);
  req.end();
}

testLogin();