<?php

namespace App\Http\Controllers\Admin\Popup;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\SmsFavorite;
use App\Models\DTO\SearchData;

class SmsController extends Controller
{
    private SmsFavorite $smsFavoriteModel;

    public function __construct(SmsFavorite $smsFavorite)
    {
        $this->smsFavoriteModel = $smsFavorite;
    }

    /**
     * SMS 설정 > 자주보내는 문자
     * @method GET|POST
     * @see /admin/popup/sms
     */
    public function favorite(Request $request)
    {
        $params = SearchData::fromRequest($request);
        $smsFavoriteData = $this->smsFavoriteModel->data($params);

        if ($smsFavoriteData->rows > 0) {
            $num = listNum($smsFavoriteData->total, $params->page, $params->perPage);
            foreach ($smsFavoriteData->list as $i => $row) {
                $row->num = $num--;
                $smsFavoriteData->list[$i] = $row;
            }
        }

        return view('admin.popup.sms.favorite', [
            'smsFavoriteData' => $smsFavoriteData,
            'params' => $params
        ]);
    }
}
