import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
    iterations: 10,
    vus: 10
};

export default function () {

    const baseUrl = 'https://iwsv5.rapidworkplace.com/';
    const username = 'pdadmin';
    const password = 'changeme';


    const loginUrl = `${baseUrl}api/Authentication/login`;

    const payload = JSON.stringify({
        userName: username,
        password: password,
    });

    const params = {
        headers: {
            'Content-Type': 'application/json',
        },
    };

    const loginRes = http.post(loginUrl, payload, params);

    check(loginRes, {
        'login: status was 200': (r) => r.status === 200,
    });

    let token;
    try {
        const jsonRes = JSON.parse(loginRes.body);
        token = jsonRes.token;
    } catch (error) {
        console.error('Could not parse login response:', loginRes.body);
    }

    sleep(1);
}
