import { Controller, Get, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger';
import { InjectDataSource } from '@nestjs/typeorm';
import { DataSource } from 'typeorm';
import { Public } from '../../modules/auth/public.decorator';

@ApiTags('mobile_specialization')
@Controller('mobile/specialization')
export class MobileSpecializationController {
  constructor(@InjectDataSource() private readonly dataSource: DataSource) {}

  @Public()
  @Get()
  @ApiOperation({ summary: 'Get all specializations (mobile)' })
  @ApiQuery({
    name: 'degreeId',
    required: false,
    type: Number,
    description: 'Filter by degree ID',
  })
  async getSpecializations(@Query('degreeId') degreeId?: string) {
    let query = `SELECT id, degree_id, name, status FROM specialization WHERE status = 1`;
    const params = [];

    if (degreeId) {
      query += ` AND degree_id = ?`;
      params.push(Number(degreeId));
    }

    query += ` ORDER BY name ASC`;

    const data = await this.dataSource.query(query, params);
    return { success: true, data };
  }
}
