import { Controller, Request, Post, Body, Get, Res, UseGuards, Param, Put, Query, Delete, Patch, Req } from '@nestjs/common';
import { ApiParam, ApiQuery, ApiTags, ApiBody, ApiConsumes } from '@nestjs/swagger';
import { CampaignService } from './campaign.services';
import { toJsonResponse } from '../../common/response';

import { CommonGuard } from 'src/modules/auth/guards/common.guard';
import { BrandGuard } from '../auth/guards/brand.guard';

// DTO Files
import { CampaignListQueryDto } from './dtos/campaign-list-query.dto';
import { CampaignIdParamDto } from './dtos/campaign-id-param.dto';
import { CampaignCreateDto } from './dtos/campaign-create.dto';
import { CampaignUpdateDto } from './dtos/campaign-update.dto';
import { CampaignSlugParamDto } from './dtos/campaign-slug-param.dto';
import { query } from 'express';
import { AddInfluencerDto } from './dtos/add-influencer.dto';
import { AddBookmarkDto } from './dtos/add-bookmark.dto';
import { InfluencerListQueryDto } from './dtos/influencer-list-query.dto';
import { ContactNowDto } from './dtos/contact-now.dto';
import { EasyApplyDto } from './dtos/easy-apply.dto';
import { InfluencerGuard } from '../auth/guards/influencer.guard';
import { InfluencerCampaignListQueryDto } from './dtos/influencer-campaign-list-query.dto';
import { BulkQuotationApprovedDto, QuotationApprovedDto } from './dtos/quotation-approved.dto';
import { CampaignInfluencerIdParamDto } from './dtos/campaign-influencer-id-param.dto';
import { AddDraftsDto } from './dtos/add-draft.dto';
import { AddDraftComment } from './dtos/add-comment.dto';
import { AddPostsDto } from './dtos/add-posts.dto';
import { Campaign } from 'src/entities/campaign.entity';
import { CampaignSaveDto } from './dtos/save-campaign.dto';
import { EditPriceDto } from './dtos/edit-price.dto';
import { InfluencerCalenderDto } from './dtos/influencer-calender.dto';
import { BrandPayNowDto } from './dtos/brand-pay-now.dto';
import { ReportDto } from './dtos/report.dto';
import { ReportService } from './report.services';
import { AdminBrandGuard } from '../auth/guards/admin-brand.guard';
import { QueryCommonGuard } from '../auth/guards/common-query.guard';
import { UpdateInfluencerDueDatesDto } from './dtos/update-influencer-due-dates.dto';
import { BrandCampaignPaymentDto } from './dtos/brand-campaign-payment.dto';
import { BrandCampaignFeedQueryDto } from './dtos/brand-campaign-feed-query.dto';
import { AdminGuard } from '../auth/guards/admin.guard';
import { PreviewCampaignDto } from './dtos/preview-campaign.dto';
import { CreateAiReportDto, AiReportIdParamDto } from './dtos/ai-report.dto';
import { AiReportService } from './ai-report.service';

@ApiTags('campaign')
@Controller('campaign')
export class CampaignController {
    constructor(
        private campaignService: CampaignService,
        private reportService: ReportService,
        private aiReportService: AiReportService,
    ) { }



    @UseGuards(BrandGuard)
    @Get()
    async getCampaign(@Query() queryParam: any, @Request() req, @Res() response: any) {

        const data = await this.campaignService.getCampaign(queryParam, req.user);
        response.status(200).json(data);

    }

    @ApiQuery({ name: 'page', required: false, example: 1 })
    @ApiQuery({ name: 'sort_by', required: false, type: 'string' })
    @ApiQuery({ name: 'sort', required: false, type: 'string' })
    @ApiQuery({ name: 'search', required: false, type: 'string' })
    @UseGuards(CommonGuard)
    @Get('list')
    async list(@Query() queryParam: CampaignListQueryDto, @Request() req, @Res() response: any) {
        const data = await this.campaignService.list(queryParam, req.user);
        response.status(200).json(data);
    }



    @ApiBody({ type: CampaignCreateDto })
    @UseGuards(BrandGuard)
    @Post()
    async create(@Body() request: CampaignCreateDto, @Req() req: any, @Res() response: any) {
        const data = await this.campaignService.create(request, req.user);
        response.status(201).json({ data: data });
    }

    @UseGuards(BrandGuard)
    @Post('ai')
    async openAI(@Body() request: any, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.openAI(request, req.user);
        response.status(200).json({ data: data });

    }

    @UseGuards(CommonGuard)
    @Get('ai/logs')
    async getLogs(@Query() query: any, @Req() req: any, @Res() response: any) {
        const data = await this.campaignService.getLogs(query);
        response.status(200).json(data);
    }

    @UseGuards(CommonGuard)
    @Post('chat/ai')
    async openAIChat(@Body() request: any, @Req() req: any, @Res() response: any) {
        const data = await this.campaignService.openAIChat(request, req.user);
        response.status(200).json({ data: data });
    }

    @UseGuards(BrandGuard)
    @Post('ai-reports/process')
    async processAiReports(@Req() req: any, @Res() response: any) {
        const data = await this.aiReportService.processPendingAiReports();
        response.status(200).json(data);
    }

    @UseGuards(BrandGuard)
    @Post('ai-reports/:campaign_id')
    async createAiReport(@Param() params: CampaignIdParamDto, @Body() body: CreateAiReportDto, @Req() req: any, @Res() response: any) {
        const data = await this.aiReportService.createAiReport(params, body, req.user);
        response.status(201).json(data);
    }

    @UseGuards(BrandGuard)
    @Get('ai-reports/:campaign_id/status')
    async getAiReportStatus(@Param() params: CampaignIdParamDto, @Req() req: any, @Res() response: any) {
        const data = await this.aiReportService.getAiReportStatus(params, req.user);
        response.status(200).json(data);
    }

    @UseGuards(BrandGuard)
    @Get('ai-reports/:campaign_id')
    async getAiReportResults(@Param() params: CampaignIdParamDto, @Query() query: any, @Req() req: any, @Res() response: any) {
        const data = await this.aiReportService.getAiReportResults(params, query, req.user);
        response.status(200).json(data);
    }

    @UseGuards(BrandGuard)
    @Get('ai-reports/:campaign_id')
    async listAiReports(@Param() params: CampaignIdParamDto, @Req() req: any, @Res() response: any) {
        const data = await this.aiReportService.listAiReports(params, req.user);
        response.status(200).json(data);
    }

    @UseGuards(BrandGuard)
    @Get('ai-reports/:campaign_id/:report_id')
    async getAiReport(@Param() params: AiReportIdParamDto, @Req() req: any, @Res() response: any) {
        const data = await this.aiReportService.getAiReport(params, req.user);
        response.status(200).json(data);
    }

    @UseGuards(BrandGuard)
    @Post('add-influencer')
    async addInfluencer(@Body() request: AddInfluencerDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.addInfluencer(request, req.user);
        response.status(200).json(data);

    }

    @ApiParam({ name: 'campaign_id', required: true })
    @ApiBody({ type: CampaignUpdateDto })
    @UseGuards(BrandGuard)
    @Put(':campaign_id')
    async update(@Param() params: CampaignIdParamDto, @Req() req: any, @Body() request: CampaignUpdateDto, @Res() response: any) {
        const data = await this.campaignService.update(request, params, req.user);
        response.status(201).json({ data: data });
    }

    @ApiParam({ name: 'campaign_influencer_id', required: true })
    @UseGuards(InfluencerGuard)
    @Patch('continue-with-same-price/:campaign_influencer_id')
    async continueWithSamePrice(@Param() params: CampaignInfluencerIdParamDto, @Req() req: any, @Res() response: any) {

        await this.campaignService.continueWithSamePrice(params, req.user);
        response.status(201).json();

    }

    @ApiParam({ name: 'campaign_id', required: true })
    @UseGuards(BrandGuard)
    @Delete(':campaign_id')
    async delete(@Param() params: CampaignIdParamDto, @Res() response: any) {

        await this.campaignService.delete(params);
        response.status(204).json();

    }

    @ApiParam({ name: 'campaign_id', required: true })
    @UseGuards(AdminGuard)
    @Patch('change-status/:campaign_id')
    async changeStatus(@Param() params: CampaignIdParamDto, @Res() response: any) {

        await this.campaignService.changeStatus(params);
        response.status(200).json();

    }

    @ApiBody({ type: AddBookmarkDto })
    @UseGuards(BrandGuard)
    @Post('add-bookmark')
    async addBookmark(@Body() request: AddBookmarkDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.addBookmark(request, req.user);
        response.status(200).json(data);

    }

    @UseGuards(BrandGuard)
    @Get('bookmarks')
    async campaignBookmark(@Req() req: any, @Query() queryParam: any, @Res() response: any) {

        const data = await this.campaignService.campaignBookmark(queryParam, req.user);
        response.status(200).json(data);

    }
    @UseGuards(QueryCommonGuard)
    @Get('bookmarks/export')
    async campaignBookmarkExport(@Req() req: any, @Query() queryParam: any, @Res() response: any) {

        const data = await this.campaignService.campaignBookmarkExport(queryParam, req.user, response);
        response.status(200).json(data);

    }

    @UseGuards(QueryCommonGuard)
    @Get('applicants/export')
    async campaignApplicantsExport(@Req() req: any, @Query() queryParam: any, @Res() response: any) {

        const data = await this.campaignService.campaignApplicantsExport(queryParam, req.user, response);
        response.status(200).json(data);

    }


    @UseGuards(BrandGuard)
    @Patch('brand/chat-permission/:campaign_influencer_id')
    async checkChatPermission(@Param() params: CampaignInfluencerIdParamDto, @Req() req: any, @Res() response: any) {
        const data = await this.campaignService.checkChatPermission(params, req.user);
        response.status(200).json(data);
    }

    @UseGuards(BrandGuard)
    @Get('influencer')
    async influencerList(@Query() queryParam: InfluencerListQueryDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.influencerList(queryParam, req.user);
        response.status(200).json(data);

    }

    @ApiBody({ type: ContactNowDto })
    @UseGuards(BrandGuard)
    @Patch('brand/contact-now/:campaign_id')
    /**
     * Endpoint to initiate contact with an influencer in a campaign.
     */

    async contactNow(@Param() params: CampaignIdParamDto, @Body() request: ContactNowDto, @Req() req: any, @Res() response: any) {

        await this.campaignService.contactNow(params, request, req.user);
        response.status(201).json();

    }

    @ApiBody({ type: QuotationApprovedDto })
    @UseGuards(BrandGuard)
    @Patch('brand/quotation-approved/:campaign_id')
    /**
     * Endpoint to initiate contact with an influencer in a campaign.
     */

    async quotationAproved(@Param() params: CampaignIdParamDto, @Body() request: QuotationApprovedDto, @Req() req: any, @Res() response: any) {
        try {
            await this.campaignService.quotationAproved(params, request, req.user);
            response.status(201).json();
        } catch (error: any) {
            response.status(error.status || 500).json(toJsonResponse(error.status || 500, error.message));
        }
    }

    @ApiBody({ type: BulkQuotationApprovedDto })
    @UseGuards(BrandGuard)
    @Post('brand/bulk-quotation-approved')
    async bulkQuotationAproved(@Body() request: BulkQuotationApprovedDto, @Req() req: any, @Res() response: any) {
        try {
            await this.campaignService.bulkQuotationAproved(request, req.user);
            response.status(201).json();
        } catch (error: any) {
            response.status(error.status || 500).json(toJsonResponse(error.status || 500, error.message));
        }
    }
    @UseGuards(BrandGuard)
    @Patch('brand/update-influencer-due-dates/:campaign_influencer_id')
    async updateInfluencerDueDates(@Param() params: CampaignInfluencerIdParamDto, @Body() body: UpdateInfluencerDueDatesDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.updateInfluencerDueDates(params, body, req.user);
        response.status(201).json();

    }


    @ApiBody({ type: EasyApplyDto })
    @UseGuards(InfluencerGuard)
    @Patch('influencer/easy-apply/:campaign_id')

    /**
     * Handles the easy apply process for an influencer in a campaign.
     */

    async easyApply(@Param() params: CampaignIdParamDto, @Body() request: EasyApplyDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.easyApply(params, request, req.user);
        response.status(200).json(data);

    }


    @UseGuards(CommonGuard)
    @Patch('influencer/other-attachment/:campaign_influencer_id')

    /**
     * Handles the easy apply process for an influencer in a campaign.
     */

    async otherAttachment(@Param() params: CampaignInfluencerIdParamDto, @Body() request: any, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.otherAttachment(params, request, req.user);
        response.status(201).json(data);

    }

    @ApiBody({ type: EasyApplyDto })
    @UseGuards(InfluencerGuard)
    @Patch('influencer/edit-price/:campaign_influencer_id')

    /**
     * Handles the easy apply process for an influencer in a campaign.
     */

    async editPrice(@Param() params: CampaignInfluencerIdParamDto, @Body() request: EditPriceDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.editPrice(params, request, req.user);
        response.status(200).json(data);

    }

    @ApiParam({ name: 'campaign_influencer_id', required: true })
    @UseGuards(BrandGuard)
    @Patch('brand/approve-price/:campaign_influencer_id')
    async approvePriceChange(@Param() params: CampaignInfluencerIdParamDto, @Req() req: any, @Res() response: any) {

        await this.campaignService.approvePriceChange(params, req.user);
        response.status(201).json();

    }

    @ApiBody({ type: AddDraftsDto })
    @UseGuards(CommonGuard)
    @Post('influencer/add-draft/:campaign_influencer_id')
    async addDraft(@Param() params: CampaignInfluencerIdParamDto, @Body() request: AddDraftsDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.addDraft(params, request, req.user);
        response.status(201).json(data);

    }

    @UseGuards(InfluencerGuard)
    @Delete('influencer/delete-draft/:draft_id')
    async deleteDraft(@Param() params: any, @Req() req: any, @Res() response: any) {

        await this.campaignService.deleteDraft(params, req.user);
        response.status(201).json();

    }

    @UseGuards(BrandGuard)
    @Patch('brand/approve-draft/:campaign_influencer_id')
    async approveDraft(@Param() params: CampaignInfluencerIdParamDto, @Body() request: any, @Req() req: any, @Res() response: any) {

        await this.campaignService.approveDraft(params, request, req.user);
        response.status(201).json();

    }

    @UseGuards(BrandGuard)
    @Patch('brand/archive/:campaign_influencer_id')
    async isArchived(@Param() params: CampaignInfluencerIdParamDto, @Body() request: any, @Req() req: any, @Res() response: any) {

        await this.campaignService.isArchived(params, req.user);
        response.status(201).json();

    }


    @UseGuards(CommonGuard)
    @Post('influencer/add-draft-comment/:draft_id')
    async addDraftComment(@Param() params: any, @Body() request: AddDraftComment, @Req() req: any, @Res() response: any) {

        await this.campaignService.addDraftComment(params, request, req.user);
        response.status(201).json();

    }

    @UseGuards(CommonGuard)
    @Get('influencer/get-draft-comment/:draft_id')
    async getDraftComment(@Param() params: any, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.getDraftComment(params, req.user);
        response.status(200).json(data);

    }

    @UseGuards(AdminBrandGuard)
    @Get('brand/campaign-influencer')
    async campaignInfluencerDetail(@Query() param: AddBookmarkDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.campaignInfluencerDetail(param, req.user);
        response.status(200).json(data);

    }

    @UseGuards(CommonGuard)
    @Get('draft-details/:draft_id')
    async getDraftDetails(@Param() params: any, @Res() response: any, @Req() req: any) {

        const data = await this.campaignService.getDraftDetails(params, req.user);
        response.status(200).json(data);

    }

    @UseGuards(CommonGuard)
    @Get('influencer/campaign-brand')
    async campaignBrandDetail(@Query() param: CampaignIdParamDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.campaignBrandDetail(param, req.user);
        response.status(200).json(data);

    }

    @ApiQuery({ name: 'page', required: false, example: 1 })
    @ApiQuery({ name: 'sort_by', required: false, type: 'string' })
    @ApiQuery({ name: 'sort', required: false, type: 'string' })
    @ApiQuery({ name: 'search', required: false, type: 'string' })
    @UseGuards(CommonGuard)
    @Get('influencer/campaign-list')
    async influencerCampaignList(@Query() queryParam: InfluencerCampaignListQueryDto, @Request() req, @Res() response: any) {
        try {
            const data = await this.campaignService.influencerCampaignList(queryParam, req.user);
            response.status(200).json(data);
        } catch (error: any) {
            console.log(error);
            response.status(error.status).json(toJsonResponse(error.status, error.message));
        }

    }

    @ApiQuery({ name: 'page', required: false, example: 1 })
    @ApiQuery({ name: 'sort_by', required: false, type: 'string' })
    @ApiQuery({ name: 'sort', required: false, type: 'string' })
    @ApiQuery({ name: 'search', required: false, type: 'string' })
    @UseGuards(InfluencerGuard)
    @Get('influencer/recommended')
    async influencerRecommendedCampaign(@Query() queryParam: InfluencerCampaignListQueryDto, @Request() req, @Res() response: any) {

        const data = await this.campaignService.influencerRecommendedCampaign(queryParam, req.user);
        response.status(200).json(data);

    }
    @UseGuards(BrandGuard)
    @Patch('brand/campaign-popup')
    async campaignPopup(@Req() req: any, @Res() response: any) {

        const data = await this.campaignService.campaignPopup(req.user);
        response.status(201).json();

    }

    @ApiQuery({ name: 'page', required: false, example: 1 })
    @ApiQuery({ name: 'sort_by', required: false, type: 'string' })
    @ApiQuery({ name: 'sort', required: false, type: 'string' })
    @ApiQuery({ name: 'search', required: false, type: 'string' })
    @UseGuards(CommonGuard)
    @Get('influencer/my-jobs')
    async influencerMyJob(@Query() queryParam: InfluencerCampaignListQueryDto, @Request() req, @Res() response: any) {

        const data = await this.campaignService.influencerMyJob(queryParam, req.user);
        response.status(200).json(data);

    }

    @ApiBody({ type: AddPostsDto })
    @UseGuards(InfluencerGuard)
    @Post('influencer/add-posts')
    async addPosts(@Body() request: AddPostsDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.addPosts(request, req.user);
        response.status(200).json(data);

    }

    @UseGuards(CommonGuard)
    @Patch('change-influencer-status/:campaign_influencer_id')
    async changeInfluencerStatus(@Param() params: CampaignInfluencerIdParamDto, @Body() request: any, @Req() req: any, @Res() response: any) {

        await this.campaignService.changeInfluencerStatus(params, request, req.user);
        response.status(201).json();

    }

    @UseGuards(CommonGuard)
    @Patch('withdraw-job/:campaign_influencer_id')
    async withdrawJob(@Param() params: CampaignInfluencerIdParamDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.withdrawJob(params, req.user);
        response.status(201).json();

    }

    @UseGuards(CommonGuard)
    @Patch('terminate-job/:campaign_influencer_id')
    async terminateJobRequest(@Param() params: CampaignInfluencerIdParamDto, @Req() req: any, @Res() response: any) {
        const data = await this.campaignService.terminateJobRequest(params, req.user);
        response.status(201).json();
    }


    @UseGuards(BrandGuard)
    @Post('brand/campaign-payment')
    async campaignPayment(@Body() request: BrandCampaignPaymentDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.campaignPayment(request, req.user);
        response.status(200).json(data);

    }


    @UseGuards(BrandGuard)
    @Delete('brand/campaign-payment/:payment_id')
    async deleteCampaignPayment(@Param() param: any, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.deleteCampaignPayment(param, req.user);
        response.status(200).json(data);

    }


    @ApiBody({ type: CampaignSaveDto })
    @UseGuards(InfluencerGuard)
    @Post('influencer/save-campaign')
    async campaignSave(@Body() request: CampaignSaveDto, @Req() req: any, @Res() response: any) {

        await this.campaignService.campaignSave(request, req.user);
        response.status(201).json();

    }

    @UseGuards(BrandGuard)
    @ApiBody({ type: BrandPayNowDto })
    @Post('brand/payment')
    async brandPayNow(@Body() body: BrandPayNowDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.brandPayNow(body, req.user);
        response.status(200).json(data);

    }

    @UseGuards(BrandGuard)
    @Get('brand/payment-list')
    async paymentListForBrand(@Query() queryParam: any, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.paymentListForBrand(queryParam, req.user);
        response.status(200).json(data);

    }

    @UseGuards(BrandGuard)
    @Get('brand/payment-statistics')
    async paymentStatisticForBrand(@Query() queryParam: any, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.paymentStatisticForBrand(queryParam, req.user);
        response.status(200).json(data);

    }

    @UseGuards(InfluencerGuard)
    @Get('influencer/payment-list')
    async paymentListForInfluencer(@Query() queryParam: any, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.paymentListForInfluencer(queryParam, req.user);
        response.status(200).json(data);

    }

    @UseGuards(InfluencerGuard)
    @Get('influencer/payment-statistics')
    async paymentStatisticForInfluencer(@Query() queryParam: any, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.paymentStatisticForInfluencer(queryParam, req.user);
        response.status(200).json(data);

    }

    @UseGuards(InfluencerGuard)
    @Get('influencer/calendar')
    async influencerCalendar(@Query() queryParam: InfluencerCalenderDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.influencerCalendar(queryParam, req.user);
        response.status(200).json(data);

    }

    @UseGuards(BrandGuard)
    @Get('brand/calendar')
    async brandCalender(@Query() queryParam: InfluencerCalenderDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.brandCalender(queryParam, req.user);
        response.status(200).json(data);

    }

    @UseGuards(BrandGuard)
    @Get('brand/dashboard/influencer-list')
    async influencerDashboardList(@Query() queryParam: any, @Req() req: any, @Res() response: any) {
        const data = await this.campaignService.influencerDashboardList(queryParam, req.user);
        response.status(200).json(data);
    }
    @UseGuards(BrandGuard)
    @Get('brand/dashboard')
    async brandDashboard(@Query() queryParam: any, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.brandDashboard(req.user);
        response.status(200).json(data);

    }

    @ApiQuery({ name: 'page', required: false, example: 1 })
    @ApiQuery({ name: 'per_page', required: false, example: 10 })
    @ApiQuery({ name: 'search', required: false, type: 'string' })
    @UseGuards(BrandGuard)
    @Get('brand/view-as-creator')
    async viewAsCreator(@Query() queryParam: BrandCampaignFeedQueryDto, @Req() req: any, @Res() response: any) {
        const data = await this.campaignService.viewAsCreator(queryParam, req.user);
        response.status(200).json(data);
    }

    @ApiQuery({ name: 'page', required: false, example: 1 })
    @ApiBody({ type: PreviewCampaignDto })
    @UseGuards(BrandGuard)
    @Post('brand/preview-as-creator')
    async previewAsCreator(@Body() request: PreviewCampaignDto, @Query() queryParam: BrandCampaignFeedQueryDto, @Req() req: any, @Res() response: any,
    ) {
        const data = await this.campaignService.previewAsCreator(request, queryParam, req.user);
        response.status(200).json(data);
    }

    @UseGuards(BrandGuard)
    @Post('reports')
    async report(@Body() request: ReportDto, @Req() req: any, @Res() response: any) {

        const data = await this.reportService.report(request, req.user);
        response.status(200).json(data);

    }

    @UseGuards(BrandGuard)
    @Get('name')
    async name(@Req() req: any, @Res() response: any) {

        const data = await this.reportService.campaignNameList(req.user);
        response.status(200).json(data);

    }

    @UseGuards(BrandGuard)
    @Get('report/export')
    async export(@Query() request: any, @Req() req: any, @Res() response: any) {

        const data = await this.reportService.exportReport(request, response, req.user);
        response.status(200).json(data);

    }

    @UseGuards(BrandGuard)
    @Patch('brand/complete/:campaign_id')
    async complete(@Param() params: CampaignIdParamDto, @Req() req: any, @Res() response: any) {
        try {
            await this.campaignService.complete(params, req.user);
            response.status(201).json();
        } catch (error: any) {
            console.log(error);
            response.status(error.status).json(toJsonResponse(error.status, error.message));
        }

    }

    @UseGuards(BrandGuard)
    @Patch('chase-up/:campaign_id')
    async chaseUp(@Param() params: CampaignIdParamDto, @Body() request: any, @Req() req: any, @Res() response: any) {

        await this.campaignService.chaseUp(params, request, req.user);
        response.status(201).json();

    }

    @ApiParam({ name: 'campaign_influencer_id', required: true })
    @UseGuards(BrandGuard)
    @Delete('delete/influencer/:campaign_influencer_id')
    async deleteCampaignInfluencer(@Param() params: CampaignInfluencerIdParamDto, @Res() response: any) {

        await this.campaignService.deleteCampaignInfluencer(params);
        response.status(204).json();

    }

    @ApiParam({ name: 'slug', required: true, description: 'Campaign slug for Open Graph / link preview meta' })
    @Get('public/meta/:slug')
    async getCampaignMeta(@Param() param: CampaignSlugParamDto, @Res() response: any) {
        const data = await this.campaignService.getCampaignMeta(param);
        response.status(200).json(data);
    }

    @ApiParam({ name: 'slug', required: true })
    @UseGuards(BrandGuard)
    @Get(':slug')
    async campaignDetail(@Param() param: CampaignSlugParamDto, @Req() req: any, @Res() response: any) {

        const data = await this.campaignService.campaignDetail(param, req.user);
        response.status(200).json(data);

    }
}
