<?php

namespace App\Http\Controllers\api\v1;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\api\v1\Country;
use App\Models\api\v1\Role;
use App\Models\api\v1\Space;
use App\Models\api\v1\Stock;
use App\Models\api\v1\Item;
use App\Models\User;
use Auth;
use Exception;
use Log;
use Carbon\Carbon;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request as Psr7Request;
use Session;
use Illuminate\Support\Facades\DB;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;


class SubscriptionController extends Controller
{


    /**
     * Liste des pass
     */
    public function subscriptionTypes(Request $request) : JsonResponse
    {
        $data[0] = [   
            "id"=> 7,
            "name"=> "Pass 30 Mns",
            "time"=> 30,
            "amount"=> 200,
            "is_active"=> 1,
            "created_at"=> "2023-12-24T11:39:37.000000Z",
        ];
        $data[1] = [   
            "id"=> 8,
            "name"=> "Pass 1 Heure",
            "time"=> 60,
            "amount"=> 300,
            "is_active"=> 1,
            "created_at"=> "2023-12-24T11:39:37.000000Z",
        ];
        $data[2] = [   
            "id"=> 9,
            "name"=> "Pass 2 Heures",
            "time"=> 120,
            "amount"=> 500,
            "is_active"=> 1,
            "created_at"=> "2023-12-24T11:39:37.000000Z",
        ];

        return $this->ReturnResponse(true, "", $data);

    }

    public function subcriptionsHistory(Request $request) : JsonResponse
    {
        $data[0] = [
            "id"            => 7,
            "name"          => "Pass 1 Heure",
            "time"          => 30,
            "amount"        => 200,
            "is_active"     => 1,
            "created_at"    => "2023-12-29T11:39:37.000000Z",
            "status"        => "active"
        ];
        $data[1] = [
            "id"            => 7,
            "name"          => "Pass 30 Mns",
            "time"          => 30,
            "amount"        => 200,
            "is_active"     => 1,
            "created_at"    => "2023-12-29T11:39:37.000000Z",
            "status"        => "expired"
        ];
        $data[2] = [
            "id"            => 7,
            "name"          => "Pass 30 Mns",
            "time"          => 30,
            "amount"        => 200,
            "is_active"     => 1,
            "created_at"    => "2023-12-29T11:39:37.000000Z",
            "status"        => "expired"
        ];

        return $this->ReturnResponse(true, "", $data);

    }


    public function details(Request $request) : JsonResponse
    {
        $data = [   
            [
                "id"=> 7,
                "name"=> "Pass 30 Mns",
                "time"=> 30,
                "amount"=> 200,
                "is_active"=> 1,
                "created_at"=> "2023-12-24T11:39:37.000000Z"
            ]
        ];
        return $this->ReturnResponse(true, "", $data);

    }



    /**
     * Achat des pass
     */
    public function enroll(Request $request) : JsonResponse
    {
        return $this->ReturnResponse(true, 'Enrollment Completed Successfully');
        //validation
//        $validator = Validator::make(
//            [
//                "number"=>$request->number,
//                "pass_id"=>$request->pass_id,
//            ],
//            [
//                'number' => 'required|numeric|min_digits:'.env('MSISDN_MIN_LENGTH'),
//                'pass_id' => 'required|numeric|min:1',
//            ],
//            [
//                'number.*' => 'Numero incorrect',
//                'pass_id.*' => 'pass incorrect',
//            ]
//        );
//        //si erreur
//        if($validator->fails()){
//            return  response(['success'=>false,'message'=>$validator->errors()],400);
//        }
//        return response()->json(['success' =>false, 'message'=>"Solde insuffisant"] , 403);

    }
    


}
