"use strict";
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenService = void 0;
const common_1 = require("@nestjs/common");
const uuid_1 = require("uuid");
const token_entity_1 = require("../entities/token.entity");
let TokenService = class TokenService {
    constructor() {
        // En una implementación real esto debería usar el repositorio de MikroORM.
        this.tokens = [];
    }
    createToken(name, expiresInHours) {
        const token = new token_entity_1.AuthToken();
        token.token = (0, uuid_1.v4)();
        token.name = name;
        if (expiresInHours) {
            token.expiresAt = new Date(Date.now() + expiresInHours * 60 * 60 * 1000);
        }
        this.tokens.push(token);
        return token;
    }
    validate(tokenString) {
        const token = this.tokens.find((t) => t.token === tokenString);
        if (!token)
            return null;
        if (token.expiresAt && token.expiresAt < new Date())
            return null;
        return token;
    }
};
exports.TokenService = TokenService;
exports.TokenService = TokenService = __decorate([
    (0, common_1.Injectable)()
], TokenService);
