import { AbstractRepository } from "./AbstractRepository.js";
import { TagEntity } from "../entities/TagEntity.js";

/**
 * Repository for TagEntity.
 * The AbstractRepository already provides findById, findAll, create, update,
 * and delete. Tag-specific queries can be added here as needed.
 */
export class TagRepository extends AbstractRepository<TagEntity> {
    constructor() {
        super(TagEntity);
    }

    /**
     * Looks up a tag by its description (case-insensitive).
     * Useful for detecting duplicates before creating a new tag.
     */
    async findByDescription(description: string): Promise<TagEntity | null> {
        return this.repo
            .createQueryBuilder("tag")
            .where("LOWER(tag.description) = LOWER(:description)", { description })
            .getOne();
    }
}