import { Controller, Get, Param, ParseUUIDPipe, Query } from '@nestjs/common';
import { GeneralService } from './general.service';
import { GetCitiesDTO } from './dto/get-cities';
import { GetObjectsDTO } from './dto/get-objects';

@Controller('/general')
export class GeneralController {
    constructor(private readonly generalService: GeneralService) { }

    @Get('/regions')//✅
    async getRegions() {
        return this.generalService.getRegions()
    }

    @Get('/districts')//✅
    async getDistricts(@Query('region_id') region_id: number) {
        return this.generalService.getDistricts(region_id)
    }

    @Get('/cities')//✅
    async getCities(@Query() getCitiesDTO: GetCitiesDTO) {
        const { region_id, offset, limit, search } = getCitiesDTO

        return this.generalService.getCities(region_id, offset, limit, search)
    }

    @Get('/types')//✅
    async getTypes() {
        return this.generalService.getTypes()
    }

    @Get('/objects/all')//✅
    async getObjects(@Query() getObjectsDTO: GetObjectsDTO) {
        const { offset, limit, city_id } = getObjectsDTO
        return this.generalService.getObjects(offset, limit, city_id)
    }

    @Get('/objects/list')// ✅
    async getObjectsList(@Query('city_id') city_id: number, @Query('year') year: number, @Query('planning') planning: number, @Query('type') type?: number) {
        return this.generalService.getObjectsList(city_id, year, planning, type)
    }

    @Get('/objects/by-id/:id')//✅
    async getObjectById(@Param('id', new ParseUUIDPipe()) id: string) {
        return this.generalService.getObjectById(id)
    }

    @Get('/values')// ✅
    async getValues(@Query('object_id') object_id: string) {
        return this.generalService.getValuesByObjectId(object_id)
    }

    @Get('/params')//✅
    async getParams(@Query('param_id') param_id: number) {
        return this.generalService.getParamsById(param_id)
    }

    @Get('/params/tcb')// ✅
    async getTcbParams(@Query('vtable') vtable: string, @Query('id_city') id_city: number, @Query('id') id: number) {
        return this.generalService.getTCBParams(vtable, id_city, id)
    }

    @Get('/search/objects')// ✅
    async getSearchObjects(@Query('q') q: string, @Query('id_city') id_city: number, @Query('year') year: number) {
        return this.generalService.getSearchObjects(q, id_city, year)
    }
}
