<?php

namespace App\Services\Dashboard;

use App\Repositories\Dashboard\DashboardSellerRepositoryInterface;

class DashboardSellerService
{
    protected $dashboardSellerRepository;
    public function __construct(
        DashboardSellerRepositoryInterface $dashboardSellerRepository,
    ) {
        $this->dashboardSellerRepository = $dashboardSellerRepository;
    }

    public function getReportActivities($filter)
    {
        //traer todas las oportunidad y traer las entregas
        $project_id = isset($filter['project_id']) ? $filter['project_id'] : null;
        if ($project_id != '0') {
            return [
                'total_activity' => $this->dashboardSellerRepository->countActivityProject($filter['fromDate'], $filter['toDate'],  $filter['asesor_id'], $project_id),
                'total_activity_visit' => $this->dashboardSellerRepository->countActivityTypeProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 1,  $project_id),
                'total_activity_call' => $this->dashboardSellerRepository->countActivityTypeProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 2,  $project_id),
                'total_activity_quote' => $this->dashboardSellerRepository->countActivityTypeProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 3,  $project_id),
                'total_activity_other' => $this->dashboardSellerRepository->countActivityTypeProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 4,  $project_id),

                'total_activity_pending' => $this->dashboardSellerRepository->countActivityStageProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'PENDING',  $project_id),
                'total_activity_complet' => $this->dashboardSellerRepository->countActivityStageProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'COMPLETED',  $project_id),
                'total_activity_cancell' => $this->dashboardSellerRepository->countActivityStageProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'CANCELLED',  $project_id),
                'total_activity_discard' => $this->dashboardSellerRepository->countActivityStageProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'DISCARD',  $project_id),

                'time_average_stage_pending' => $this->dashboardSellerRepository->TimeAverageActivityStageProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'PENDING',  $project_id),
                'time_average_stage_complet' => $this->dashboardSellerRepository->TimeAverageActivityStageProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'COMPLETED',  $project_id),
                'time_average_stage_cancell' => $this->dashboardSellerRepository->TimeAverageActivityStageProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'CANCELLED',  $project_id),
                'time_average_stage_discard' => $this->dashboardSellerRepository->TimeAverageActivityStageProject($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'DISCARD',  $project_id),
            ];
        } else {
            return [
                'total_activity' => $this->dashboardSellerRepository->countActivity($filter['fromDate'], $filter['toDate'],  $filter['asesor_id']),
                'total_activity_visit' => $this->dashboardSellerRepository->countActivityType($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 1),
                'total_activity_call' => $this->dashboardSellerRepository->countActivityType($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 2),
                'total_activity_quote' => $this->dashboardSellerRepository->countActivityType($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 3),
                'total_activity_other' => $this->dashboardSellerRepository->countActivityType($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 4),

                'total_activity_pending' => $this->dashboardSellerRepository->countActivityStage($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'PENDING'),
                'total_activity_complet' => $this->dashboardSellerRepository->countActivityStage($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'COMPLETED'),
                'total_activity_cancell' => $this->dashboardSellerRepository->countActivityStage($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'CANCELLED'),
                'total_activity_discard' => $this->dashboardSellerRepository->countActivityStage($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'DISCARD'),

                'time_average_stage_pending' => $this->dashboardSellerRepository->TimeAverageActivityStage($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'PENDING'),
                'time_average_stage_complet' => $this->dashboardSellerRepository->TimeAverageActivityStage($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'COMPLETED'),
                'time_average_stage_cancell' => $this->dashboardSellerRepository->TimeAverageActivityStage($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'CANCELLED'),
                'time_average_stage_discard' => $this->dashboardSellerRepository->TimeAverageActivityStage($filter['fromDate'], $filter['toDate'], $filter['asesor_id'], 'DISCARD'),
            ];
        }
    }
}
