"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InstanceListFollowersQueryBuilder = void 0;
const tslib_1 = require("tslib");
const shared_1 = require("../../shared");
const utils_1 = require("../../utils");
const instance_list_follows_query_builder_1 = require("./shared/instance-list-follows-query-builder");
class InstanceListFollowersQueryBuilder extends instance_list_follows_query_builder_1.InstanceListFollowsQueryBuilder {
    constructor(sequelize, options) {
        super(sequelize, options);
        this.sequelize = sequelize;
        this.options = options;
    }
    listFollowers() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.buildListQuery();
            const results = yield this.runQuery({ nest: true });
            const modelBuilder = new shared_1.ModelBuilder(this.sequelize);
            return modelBuilder.createModels(results, 'ActorFollow');
        });
    }
    countFollowers() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.buildCountQuery();
            const result = yield this.runQuery();
            return (0, utils_1.parseRowCountResult)(result);
        });
    }
    getWhere() {
        let where = 'WHERE "ActorFollowing"."id" IN (:actorIds) ';
        this.replacements.actorIds = this.options.actorIds;
        if (this.options.state) {
            where += 'AND "ActorFollowModel"."state" = :state ';
            this.replacements.state = this.options.state;
        }
        if (this.options.search) {
            const escapedLikeSearch = this.sequelize.escape('%' + this.options.search + '%');
            where += `AND (` +
                `"ActorFollower->Server"."host" ILIKE ${escapedLikeSearch} ` +
                `OR "ActorFollower"."preferredUsername" ILIKE ${escapedLikeSearch} ` +
                `)`;
        }
        if (this.options.actorType) {
            where += `AND "ActorFollower"."type" = :actorType `;
            this.replacements.actorType = this.options.actorType;
        }
        return where;
    }
}
exports.InstanceListFollowersQueryBuilder = InstanceListFollowersQueryBuilder;
//# sourceMappingURL=instance-list-followers-query-builder.js.map