import { Random } from '@pawel-up/data-mock/Random.js';
import { Types } from '@pawel-up/data-mock/Types.js';
import { Internet } from '@pawel-up/data-mock/Internet.js';
import { Person } from '@pawel-up/data-mock/Person.js';
// import { randomValue } from '@pawel-up/data-mock/src/lib/Http.js';
import { Kind as HttpHistoryKind } from '../../models/HttpHistory.js';
import { Request } from './Request.js';
export class History {
    person;
    types;
    internet;
    random;
    request;
    constructor(init = {}) {
        this.person = new Person(init);
        this.types = new Types(init.seed);
        this.internet = new Internet(init);
        this.random = new Random(init.seed);
        this.request = new Request(init);
    }
    async httpHistory(init = {}) {
        const date = this.types.datetime(init.created);
        const result = {
            kind: HttpHistoryKind,
            created: date.getTime(),
            log: await this.request.log(init.log),
            user: '',
            app: '',
            key: '',
            project: '',
            request: '',
            organization: '',
        };
        date.setHours(0, 0, 0, 0);
        result.midnight = date.getTime();
        if (typeof init.organization === 'string') {
            result.organization = init.organization;
        }
        else if (Array.isArray(init.organization)) {
            result.organization = this.random.pickOne(init.organization);
        }
        else if (init.organization) {
            result.organization = this.types.string(10);
        }
        if (typeof init.user === 'string') {
            result.user = init.user;
        }
        else if (Array.isArray(init.user)) {
            result.user = this.random.pickOne(init.user);
        }
        else {
            result.user = this.types.string(21);
        }
        if (typeof init.project === 'string') {
            result.project = init.project;
        }
        else if (Array.isArray(init.project)) {
            result.project = this.random.pickOne(init.project);
        }
        else if (init.project) {
            result.project = this.types.string(21);
        }
        if (typeof init.request === 'string') {
            result.request = init.request;
        }
        else if (Array.isArray(init.request)) {
            result.request = this.random.pickOne(init.request);
        }
        else if (init.request) {
            result.request = this.types.string(21);
        }
        if (typeof init.app === 'string') {
            result.app = init.app;
        }
        else if (Array.isArray(init.app)) {
            result.app = this.random.pickOne(init.app);
        }
        else if (init.app) {
            result.app = this.types.string(21);
        }
        return result;
    }
    async httpHistoryList(size = 25, init = {}) {
        const { usersSize, organizationSize, projectsSize, requestsSize, appsSize } = init;
        const copy = { ...init };
        if (usersSize && typeof init.user === 'undefined') {
            const users = [];
            for (let i = 0; i < usersSize; i++) {
                users.push(this.types.string(21));
            }
            copy.user = users;
        }
        if (organizationSize && typeof init.organization === 'undefined') {
            const organization = [];
            for (let i = 0; i < organizationSize; i++) {
                organization.push(this.types.string(10));
            }
            copy.organization = organization;
        }
        if (projectsSize && typeof init.project === 'undefined') {
            const project = [];
            for (let i = 0; i < projectsSize; i++) {
                project.push(this.types.string(21));
            }
            copy.project = project;
        }
        if (requestsSize && typeof init.request === 'undefined') {
            const requests = [];
            for (let i = 0; i < requestsSize; i++) {
                requests.push(this.types.string(21));
            }
            copy.request = requests;
        }
        if (appsSize && typeof init.app === 'undefined') {
            const apps = [];
            for (let i = 0; i < appsSize; i++) {
                apps.push(this.types.string(21));
            }
            copy.app = apps;
        }
        const result = [];
        for (let i = 0; i < size; i++) {
            result.push(await this.httpHistory(copy));
        }
        return result;
    }
}
//# sourceMappingURL=History.js.map