import { Types } from '@pawel-up/data-mock/Types.js';
import { Time } from '@pawel-up/data-mock/Time.js';
import { Lorem } from '@pawel-up/data-mock/Lorem.js';
import Http from '@pawel-up/data-mock/Http.js';
// import { randomValue } from '@pawel-up/data-mock/src/lib/Http.js';
import { Kind as HttpRequestKind } from '../../models/HttpRequest.js';
import { Kind as RequestKind, Request as RequestModel } from '../../models/Request.js';
import { Kind as RequestLogKind } from '../../models/RequestLog.js';
import { Response } from './Response.js';
export class Request {
    types;
    lorem;
    time;
    http;
    response;
    constructor(init = {}) {
        this.types = new Types(init.seed);
        this.lorem = new Lorem(init);
        this.time = new Time(init);
        this.http = new Http(init);
        this.response = new Response(init);
    }
    request(init) {
        const schema = {
            kind: RequestKind,
            expects: this.httpRequest(init),
            info: {
                name: this.lorem.words(2),
                description: this.lorem.paragraph(),
            },
            created: this.time.timestamp(),
        };
        const instance = new RequestModel(schema);
        return instance.toJSON();
    }
    httpRequest(init) {
        const request = this.http.request.request(init);
        return {
            kind: HttpRequestKind,
            ...request,
        };
    }
    sentRequest(init) {
        const start = this.time.timestamp();
        return {
            startTime: start,
            endTime: this.time.timestamp({ min: start + 1 }),
            ...this.httpRequest(init),
        };
    }
    async log(init = {}) {
        const result = {
            kind: RequestLogKind,
        };
        if (!init.noRequest) {
            result.request = this.sentRequest(init.request);
        }
        if (!init.noResponse) {
            result.response = await this.response.response(init.response);
        }
        if (init.redirects) {
            result.redirects = await this.response.redirects(undefined, init.response);
        }
        if (!init.noSize) {
            result.size = this.response.size();
        }
        return result;
    }
}
//# sourceMappingURL=Request.js.map