"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SupportAgentService = void 0;
class SupportAgentService {
    agentRepository;
    logger;
    constructor(agentRepository, logger) {
        this.agentRepository = agentRepository;
        this.logger = logger;
    }
    async createAgent(input) {
        const agent = await this.agentRepository.create({
            adminUserId: input.adminUserId,
            displayName: input.displayName,
            active: input.active ?? true,
            online: false,
            status: "OFFLINE",
            maxConcurrentTickets: input.maxConcurrentTickets ?? 5,
            currentTickets: 0,
            role: input.role
        });
        this.logger.info("Support agent created.", { agentId: agent.id, adminUserId: input.adminUserId });
        return agent;
    }
    async getById(id) {
        return this.agentRepository.findById(id);
    }
    async getByAdminUserId(adminUserId) {
        return this.agentRepository.findByAdminUserId(adminUserId);
    }
    async listAgents() {
        return this.agentRepository.findAll();
    }
    async listActiveAgents() {
        return this.agentRepository.findActive();
    }
    async listOnlineAgents() {
        return this.agentRepository.findOnline();
    }
    async updateAgent(id, input) {
        const agent = await this.agentRepository.update(id, input);
        if (agent) {
            this.logger.info("Support agent updated.", { agentId: id, ...input });
        }
        return agent;
    }
    async setOnline(id, online) {
        const status = online ? "ONLINE" : "OFFLINE";
        return this.agentRepository.update(id, { online, status });
    }
    async incrementCurrentTickets(id) {
        return this.agentRepository.updateCurrentTickets(id, 1);
    }
    async decrementCurrentTickets(id) {
        return this.agentRepository.updateCurrentTickets(id, -1);
    }
    async deleteAgent(id) {
        return this.agentRepository.delete(id);
    }
}
exports.SupportAgentService = SupportAgentService;
