<?php

namespace App\Http\Controllers\Api\V1\Website;

use App\Domain\Website\Models\SiteFaq;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\Rule;

class CmsFaqController extends CmsResourceController
{
    protected function model(): string
    {
        return SiteFaq::class;
    }

    protected function rules(bool $creating): array
    {
        return [
            'question' => [$creating ? 'required' : 'sometimes', 'string', 'max:255'],
            'answer' => [$creating ? 'required' : 'sometimes', 'string', 'max:5000'],
            'audience' => ['sometimes', Rule::in(['candidate', 'employer', 'general'])],
            'is_published' => ['sometimes', 'boolean'],
            'sort_order' => ['sometimes', 'integer', 'min:0', 'max:9999'],
        ];
    }

    protected function present(Model $record): array
    {
        return [
            'id' => $record->uuid,
            'question' => $record->question,
            'answer' => $record->answer,
            'audience' => $record->audience,
            'is_published' => $record->is_published,
            'sort_order' => $record->sort_order,
        ];
    }
}
