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, Field, InputType, ObjectType, Query, Resolver } from 'type-graphql';
import { LogError } from '@memberjunction/core';
import { GetReadOnlyProvider } from '../util.js';
let DatasetResultType = class DatasetResultType {
    DatasetID;
    DatasetName;
    Success;
    Status;
    LatestUpdateDate;
    Results;
};
__decorate([
    Field(() => String),
    __metadata("design:type", String)
], DatasetResultType.prototype, "DatasetID", void 0);
__decorate([
    Field(() => String),
    __metadata("design:type", String)
], DatasetResultType.prototype, "DatasetName", void 0);
__decorate([
    Field(() => Boolean),
    __metadata("design:type", Boolean)
], DatasetResultType.prototype, "Success", void 0);
__decorate([
    Field(() => String),
    __metadata("design:type", String)
], DatasetResultType.prototype, "Status", void 0);
__decorate([
    Field(() => Date),
    __metadata("design:type", Date)
], DatasetResultType.prototype, "LatestUpdateDate", void 0);
__decorate([
    Field(() => String),
    __metadata("design:type", String)
], DatasetResultType.prototype, "Results", void 0);
DatasetResultType = __decorate([
    ObjectType()
], DatasetResultType);
export { DatasetResultType };
let DatasetItemFilterTypeGQL = class DatasetItemFilterTypeGQL {
    ItemCode;
    Filter;
};
__decorate([
    Field(() => String),
    __metadata("design:type", String)
], DatasetItemFilterTypeGQL.prototype, "ItemCode", void 0);
__decorate([
    Field(() => String),
    __metadata("design:type", String)
], DatasetItemFilterTypeGQL.prototype, "Filter", void 0);
DatasetItemFilterTypeGQL = __decorate([
    InputType()
], DatasetItemFilterTypeGQL);
export { DatasetItemFilterTypeGQL };
let DatasetResolverExtended = class DatasetResolverExtended {
    async GetDatasetByName(DatasetName, { providers }, ItemFilters) {
        try {
            const md = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
            const result = await md.GetDatasetByName(DatasetName, ItemFilters);
            if (result) {
                return {
                    DatasetID: result.DatasetID,
                    DatasetName: result.DatasetName,
                    Success: result.Success,
                    Status: result.Status,
                    LatestUpdateDate: result.LatestUpdateDate,
                    Results: JSON.stringify(result.Results),
                };
            }
            else {
                throw new Error('Error retrieving Dataset: ' + DatasetName);
            }
        }
        catch (err) {
            LogError(err);
            throw new Error('Error retrieving Dataset: ' + DatasetName + '\n\n' + err);
        }
    }
};
__decorate([
    Query(() => DatasetResultType),
    __param(0, Arg('DatasetName', () => String)),
    __param(1, Ctx()),
    __param(2, Arg('ItemFilters', () => [DatasetItemFilterTypeGQL], { nullable: 'itemsAndList' })),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object, Array]),
    __metadata("design:returntype", Promise)
], DatasetResolverExtended.prototype, "GetDatasetByName", null);
DatasetResolverExtended = __decorate([
    Resolver(DatasetResultType)
], DatasetResolverExtended);
export { DatasetResolverExtended };
let DatasetStatusResultType = class DatasetStatusResultType {
    DatasetID;
    DatasetName;
    Success;
    Status;
    LatestUpdateDate;
    EntityUpdateDates;
};
__decorate([
    Field(() => String),
    __metadata("design:type", String)
], DatasetStatusResultType.prototype, "DatasetID", void 0);
__decorate([
    Field(() => String),
    __metadata("design:type", String)
], DatasetStatusResultType.prototype, "DatasetName", void 0);
__decorate([
    Field(() => Boolean),
    __metadata("design:type", Boolean)
], DatasetStatusResultType.prototype, "Success", void 0);
__decorate([
    Field(() => String),
    __metadata("design:type", String)
], DatasetStatusResultType.prototype, "Status", void 0);
__decorate([
    Field(() => Date),
    __metadata("design:type", Date)
], DatasetStatusResultType.prototype, "LatestUpdateDate", void 0);
__decorate([
    Field(() => String),
    __metadata("design:type", String)
], DatasetStatusResultType.prototype, "EntityUpdateDates", void 0);
DatasetStatusResultType = __decorate([
    ObjectType()
], DatasetStatusResultType);
export { DatasetStatusResultType };
let DatasetStatusResolver = class DatasetStatusResolver {
    async GetDatasetStatusByName(DatasetName, { providers }, ItemFilters) {
        try {
            const md = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
            const result = await md.GetDatasetStatusByName(DatasetName, ItemFilters);
            if (result) {
                return {
                    DatasetID: result.DatasetID,
                    DatasetName: result.DatasetName,
                    Success: result.Success,
                    Status: result.Status,
                    LatestUpdateDate: result.LatestUpdateDate,
                    EntityUpdateDates: JSON.stringify(result.EntityUpdateDates),
                };
            }
            else {
                throw new Error('Error retrieving Dataset Status: ' + DatasetName);
            }
        }
        catch (err) {
            LogError(err);
            throw new Error('Error retrieving Dataset Status: ' + DatasetName + '\n\n' + err);
        }
    }
};
__decorate([
    Query(() => DatasetStatusResultType),
    __param(0, Arg('DatasetName', () => String)),
    __param(1, Ctx()),
    __param(2, Arg('ItemFilters', () => [DatasetItemFilterTypeGQL], { nullable: 'itemsAndList' })),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object, Array]),
    __metadata("design:returntype", Promise)
], DatasetStatusResolver.prototype, "GetDatasetStatusByName", null);
DatasetStatusResolver = __decorate([
    Resolver(DatasetStatusResultType)
], DatasetStatusResolver);
export { DatasetStatusResolver };
//# sourceMappingURL=DatasetResolver.js.map