<?php

namespace App\Http\Controllers\Api;

use App\Models\Timeline;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class TimelineController extends BaseApiController
{
    protected string $model = Timeline::class;
    protected array $with = ['project'];
    protected array $searchable = ['description', 'category'];
    protected array $filters = ['project' => 'project_id', 'category' => 'category'];

    protected function rules(Request $request, ?Model $model = null): array
    {
        return [
            'project' => 'nullable|string|exists:projects,id',
            'startDate' => 'nullable|date',
            'endDate' => 'nullable|date',
            'priority' => 'nullable|string',
            'category' => 'nullable|string',
            'description' => 'nullable|string',
        ];
    }

    protected function transform(Request $request, array $data): array
    {
        if (array_key_exists('project', $data)) {
            $data['project_id'] = $data['project'];
            unset($data['project']);
        }
        return $data;
    }
}
