<?php

namespace App\Http\Controllers\Api;

use App\Models\ExecutivePosition;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ExecutiveController extends BaseApiController
{
    /**
     * Get all executive positions for the current user's association
     */
    public function index(Request $request)
    {
        $user = Auth::user();
        
        if (!$user) {
            return $this->errorResponse('Unauthenticated', 401);
        }

        $association = $user->associations()->first();
        
        if (!$association) {
            return $this->errorResponse('No association found', 404);
        }

        $executives = ExecutivePosition::where('association_id', $association->id)
            ->active()
            ->ordered()
            ->with('user:id,firstname,surname,profile_photo_path,email,phone')
            ->get();

        return $this->successResponse($executives);
    }
}
