<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StorePlanRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('plans.create') || $this->user()?->can('plans.edit') || $this->user()?->hasRole('Administrator');
    }

    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:255'],
            'telecom_company_id' => ['required', 'exists:telecom_companies,id'],
            'plan_type' => ['required', Rule::in(['prepaid', 'postpaid', 'data', 'voice', 'bundle'])],
            'price' => ['required', 'numeric', 'min:0'],
            'billing_cycle' => ['required', Rule::in(['monthly', 'quarterly', 'yearly'])],
            'description' => ['nullable', 'string'],
            'status' => ['required', Rule::in(['active', 'inactive'])],
            'start_date' => ['nullable', 'date'],
            'end_date' => ['nullable', 'date', 'after_or_equal:start_date'],
            'effective_date' => ['nullable', 'date'],
            'price_reason' => ['nullable', 'string', 'max:255'],
        ];
    }
}
