import app from '@adonisjs/core/services/app';
import { isFunction } from '../../../lib/utils.js';
export class AKEnabledRelation {
    name;
    mutability;
    serviceClass;
    service;
    queryModifier;
    constructor(name, mutability, serviceClass, service, queryModifier) {
        this.name = name;
        this.mutability = mutability;
        this.serviceClass = serviceClass;
        this.service = service;
        this.queryModifier = queryModifier;
    }
    static readOnly(name, serviceClass, queryModifier) {
        return new AKEnabledRelation(name, 'readOnly', serviceClass, undefined, queryModifier);
    }
    static assignOnly(name, serviceClass, queryModifier) {
        return new AKEnabledRelation(name, 'assignOnly', serviceClass, undefined, queryModifier);
    }
    static full(name, serviceClass, queryModifier) {
        return new AKEnabledRelation(name, 'full', serviceClass, undefined, queryModifier);
    }
    async makeService() {
        if (this.service)
            return;
        const serviceClass = this.serviceClass
            ? isFunction(this.serviceClass)
                ? this.serviceClass()
                : this.serviceClass
            : undefined;
        this.service = serviceClass ? await app.container.make(serviceClass) : undefined;
    }
    copyWithName(newName) {
        return new AKEnabledRelation(newName, this.mutability, this.serviceClass, this.service, this.queryModifier);
    }
    static inherit(prefix, relations) {
        return relations.map((r) => r.copyWithName(prefix + '.' + r.name));
    }
}
//# sourceMappingURL=relations.js.map