var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { Arg, Ctx, Int, Query, Resolver } from '@memberjunction/server';
import { MJUser_, MJUserResolverBase } from '../generated/generated.js';
import { GetReadOnlyProvider } from '../util.js';
let UserResolver = class UserResolver extends MJUserResolverBase {
    async CurrentUser(context) {
        const result = await this.UserByEmail(context.userPayload.email, context);
        console.log('CurrentUser', result);
        return result;
    }
    async UserByID(ID, { providers, userPayload }) {
        const provider = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
        const retVal = super.safeFirstArrayElement(await this.findBy(provider, 'Users', { ID }, userPayload.userRecord));
        return this.MapFieldNamesToCodeNames('Users', retVal);
    }
    async UserByEmployeeID(EmployeeID, { providers, userPayload }) {
        const provider = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
        const retVal = super.safeFirstArrayElement(await this.findBy(provider, 'Users', { EmployeeID }, userPayload.userRecord));
        return this.MapFieldNamesToCodeNames('Users', retVal);
    }
    async UserByEmail(Email, { providers, userPayload }) {
        const searchEmail = Email;
        const provider = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
        const returnVal = super.safeFirstArrayElement(await this.findBy(provider, 'Users', { Email: searchEmail }, userPayload.userRecord));
        return this.MapFieldNamesToCodeNames('Users', returnVal);
    }
};
__decorate([
    Query(() => MJUser_),
    __param(0, Ctx()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], UserResolver.prototype, "CurrentUser", null);
__decorate([
    Query(() => MJUser_),
    __param(0, Arg('ID', () => Int)),
    __param(1, Ctx()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, Object]),
    __metadata("design:returntype", Promise)
], UserResolver.prototype, "UserByID", null);
__decorate([
    Query(() => MJUser_),
    __param(0, Arg('EmployeeID', () => Int)),
    __param(1, Ctx()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, Object]),
    __metadata("design:returntype", Promise)
], UserResolver.prototype, "UserByEmployeeID", null);
__decorate([
    Query(() => MJUser_),
    __param(0, Arg('Email', () => String)),
    __param(1, Ctx()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object]),
    __metadata("design:returntype", Promise)
], UserResolver.prototype, "UserByEmail", null);
UserResolver = __decorate([
    Resolver(MJUser_)
], UserResolver);
export { UserResolver };
export default UserResolver;
//# sourceMappingURL=UserResolver.js.map