<?php

namespace App\Classes\Modules\Contacts\Services;


use App\Models\Contact;
use App\Http\Resources\Contact as ContactResource;

class ListsContact
{

    /** @var  Contact */
    private $repository;

    /**
     * ListsContact constructor.
     * @param Contact $repository
     */
    public function __construct(Contact $repository)
    {
        $this->repository = $repository;
    }

    public function execute(int $type, int $referenceId){

        $contacts = $this->repository->where('type', $type)
            ->where('reference_id', $referenceId)->orderBy('created_at')->paginate(5);

        // Return collection of contacts as a resource
        return ContactResource::collection($contacts);
    }


}