import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common';
import { UserCommunicationAddressService } from './user-communication-address.service';
import { CreateUserCommunicationAddressDto } from './dto/create-user-communication-address.dto';
import { UpdateUserCommunicationAddressDto } from './dto/update-user-communication-address.dto';
import { UserCommunicationAddress } from './entities/user-communication-address.entity';

@Controller('user-communication-address')
export class UserCommunicationAddressController {
  constructor(private readonly userCommunicationAddressService: UserCommunicationAddressService) { }

  @Post()
  create(@Body() createUserCommunicationAddressDto: UserCommunicationAddress) {
    return this.userCommunicationAddressService.create(createUserCommunicationAddressDto);
  }

  @Get()
  findAll(@Query('user_id') user_id?: number) {
    if (!user_id) {
      return {
        message: "User ID is required",
        status: "Failed",
        statusCode: 400
      }
    }
    return this.userCommunicationAddressService.findAll(user_id);
  }



  @Patch(':id')
  update(@Param('id') id: string, @Body() updateUserCommunicationAddressDto: UserCommunicationAddress) {
    if (!id) {
      return {
        message: "Address ID is required",
        status: "Failed",
        statusCode: 400
      }
    }
    return this.userCommunicationAddressService.update(+id, updateUserCommunicationAddressDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.userCommunicationAddressService.remove(+id);
  }
}
