<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use App\Http\Requests\Api\Partner\PartnerRequest;
use App\Http\Resources\PartnerRequestResource;
use App\Http\Resources\PartnerResource;
use App\Http\Resources\PartnerShowResource;
use App\Models\Partner;
use App\Models\PartnerRequest as ModelsPartnerRequest;

class PartnerController extends Controller
{
    public function index()
    {
        $partners = Partner::query()->orderBy("position")->get();

        return PartnerResource::collection($partners);
    }

    public function show($partner_id)
    {
        $partner = Partner::findOrFail($partner_id);

        return new PartnerShowResource($partner);
    }

    public function store(PartnerRequest $request)
    {
        $user = getAuthUser();
        $partner = ModelsPartnerRequest::create([
            'user_id' => $user->id,
            'partner_id' => $request->partner_id,
            'city_id' => $request->city_id,
            'price' => $request->price,
            'comment' => $request->comment,
            'phone' => $request->phone,
            'full_name' => $request->full_name,
        ]);

        return new PartnerRequestResource($partner);
    }
}
