<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Validator;
use Auth;
use Hash;
use Session;
use App\Models\User;
use DB;

class AuthController extends Controller
{
    public function login(Request $request)
    {
        // print_r($request->all());
        $response = ["success" => false];
        try {
            $data = [
                "email" => $request->email,
                "password" => $request->password,
            ];

            Auth::attempt($data);

            if (Auth::check() && Auth::user()->status != 1) {
                Auth::logout();
                $response = [
                    "success" => false,
                    "code" => 400,
                    "msg" => "Your account is inactive, please contact the Administrator.",
                ];
            }

            $response = [
                "code" => 200,
                "success" => true,
                "data" => [
                    "id" => Auth::user()->id,
                ],
            ];
        } catch (\Throwable $th) {
            $response["error"] = $th->getMessage();
        }

        return $response;
    }
}
