import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
import { GiteaService } from './gitea.service';
import { AdminAuthGuard } from '../../common/guards/admin-auth.guard';
import { AdminRolesGuard } from '../../common/guards/admin-roles.guard';

@ApiTags('admin-project-center')
@ApiBearerAuth()
@Controller('admin-api/projects')
@UseGuards(AdminAuthGuard, AdminRolesGuard)
export class ProjectCenterController {
  constructor(private readonly gitea: GiteaService) {}

  @Get('repos')
  @ApiOperation({ summary: 'Gitea 仓库列表' })
  async getRepos() {
    return this.gitea.getRepos();
  }

  @Get('repos/:owner/:repo/milestones')
  @ApiOperation({ summary: '仓库里程碑' })
  async getMilestones(@Param('owner') owner: string, @Param('repo') repo: string) {
    return this.gitea.getMilestones(owner, repo);
  }

  @Get('repos/:owner/:repo/issues')
  @ApiOperation({ summary: '仓库 Issue 列表' })
  @ApiQuery({ name: 'milestone', required: false })
  @ApiQuery({ name: 'state', required: false })
  async getIssues(
    @Param('owner') owner: string, @Param('repo') repo: string,
    @Query('milestone') milestone?: string, @Query('state') state?: string,
  ) {
    return this.gitea.getIssues(owner, repo, milestone, state);
  }

  @Get('repos/:owner/:repo/releases')
  @ApiOperation({ summary: '仓库 Release 列表' })
  async getReleases(@Param('owner') owner: string, @Param('repo') repo: string) {
    return this.gitea.getReleases(owner, repo);
  }

  @Get('runners')
  @ApiOperation({ summary: 'Gitea Runner 状态' })
  async getRunners() {
    return this.gitea.getRunners();
  }
}
