<?php

namespace App\Http\Controllers;

use App\Helpers\Helper;
use App\Models\FailLogs;
use App\Models\SenderType;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class FailedLogController extends Controller
{
    use Helper;
    public function __construct()
    {
        $this->model = new FailLogs();

    }
    public function index()
    {
        if (!can('history_log_view')) {
            return $this->notPermitted();
        }
        try{

            $perPage = request()->input('perPage');

            $data = DB::table('fail_logs')->orderBy('time', 'ASC')->paginate($perPage);

            return returnData(2000, $data);
        }catch (\Exception $exception) {
            return returnData(5000, $exception->getMessage(), $exception->getMessage());
        }

    }

    public function destroy($id)
    {
        try {
            $data = $this->model->where('id', $id)->first();
            if ($data) {
                $data->delete();

                return returnData(2000, $data, 'Successfully Deleted');
            }

            return returnData(5000, null, 'Data Not found');

        } catch (\Exception $exception) {
            return returnData(5000, $exception->getMessage(), 'Whoops, Something Went Wrong..!!');
        }

    }
}
