/**
 * Repository for AgentSkill.
 * Uses standard TypeORM repository (no schema-per-tenant — uses tenantId column filter).
 */
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AgentSkill } from '../../domain/entities/agent-skill.entity';

@Injectable()
export class AgentSkillRepository {
  constructor(
    @InjectRepository(AgentSkill)
    private readonly repo: Repository<AgentSkill>,
  ) {}

  async findByTenantId(tenantId: string): Promise<AgentSkill[]> {
    return this.repo.find({ where: { tenantId }, order: { createdAt: 'DESC' } });
  }

  async findOneByIdAndTenant(id: string, tenantId: string): Promise<AgentSkill | null> {
    return this.repo.findOneBy({ id, tenantId });
  }

  async save(entity: AgentSkill): Promise<AgentSkill> {
    return this.repo.save(entity);
  }

  async deleteById(id: string): Promise<void> {
    await this.repo.delete(id);
  }
}
