import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { PlatformChangelog } from '../../entities/platform-changelog.entity';

@Injectable()
export class ChangelogService {
  constructor(
    @InjectRepository(PlatformChangelog)
    private readonly changelogRepo: Repository<PlatformChangelog>,
  ) {}

  async getEntries(
    page: number,
    limit: number,
  ): Promise<{ entries: PlatformChangelog[]; total: number }> {
    const skip = (page - 1) * limit;

    const [entries, total] = await this.changelogRepo.findAndCount({
      order: { published_at: 'DESC' },
      skip,
      take: limit,
    });

    return { entries, total };
  }
}
