<?php

namespace App\Http\Controllers;

use App\Models\Project;
use App\Models\Proposal;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Inertia\Inertia;

class FirmProposalsController extends Controller
{

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        $proposals = Proposal::where("proposalable_id", "=", Auth::user()->firm->id)
            ->where("proposalable_type", "=", "App\Models\Firm")
            ->with(["project", 'proposalable'=> ["user", 'currency']])
            ->orderBy("created_at", "desc")
            ->paginate(10);

            return Inertia::render("Proposals/Index", [
                "proposals" => $proposals,
            ]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create($slug)
    {
        $project= Project::where('slug',$slug)->firstOrFail();
        $project->load([
            "proposals" => ["proposalable.user"],
            ]
        );
//         dd($project);
        return Inertia::render("Projects/Proposals/Create/Show", [
            "project" => $project,
            'type' => 'firm',
        ]);
    }


    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show(Proposal $proposal)
    {
        $proposal->load([
            "proposalable" => [
                'user',
                'location'
            ],
            "files",
            'contract',
            'milestones' => [
                'deliverables',
                'files',
            ],
            'project.user.wallet'
        ]);


        return Inertia::render("Projects/Client/Proposals/Single/Index", [
            "proposal" => $proposal,
            "worker" => true,
        ]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
