<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Country;
use App\Models\Language;
use App\Traits\ApiResponse;
use Illuminate\Http\Request;
use OpenApi\Attributes as OA;
class DataController extends Controller
{
    use ApiResponse;


    #[OA\Get(
        path: '/api/country',
        operationId: 'country',
        summary: 'Get countries',
        description: 'Returns a list of countries.',
        tags: ['Data'],
        responses: [
            new OA\Response(
                response: 200,
                description: 'Success',
                content: new OA\JsonContent(
                    properties: [
                        new OA\Property(property: 'success', type: 'integer', example: 1),
                        new OA\Property(property: 'message', type: 'string', example: 'Success'),

                    ]
                )
            ),
        ]
    )
    ]
    public function country(Request $request)
    {
        $countries = Country::select('id', 'name','phone_code')->where('is_active', 1)->get();
        if ($countries) {
            return $this->successResponse('Success', $countries);
        }else{
            return $this->errorResponse('Error');
        }
    }

    public function language(Request $request) {
        $languages = Language::select('id', 'name')->where('is_active', 1)->get();
        if ($languages) {
            return $this->successResponse('Success', $languages);
        }else{
            return $this->errorResponse('Error');
        }
    }
}
