<?php

namespace App\Http\Requests\Api\V1\Tenant;

use App\Support\ModuleRegistry;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class RegisterBusinessRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            // Business info
            'business_name' => ['required', 'string', 'max:255'],
            'business_type' => ['required', 'string', Rule::in(ModuleRegistry::validTypes())],
            'address'       => ['nullable', 'string', 'max:500'],
            'phone'         => ['nullable', 'string', 'max:30'],

            // Owner account
            'owner_name'            => ['required', 'string', 'max:255'],
            'email'                 => ['required', 'email', 'max:255', 'unique:users,email'],
            'password'              => ['required', 'string', 'min:8', 'confirmed'],
            'password_confirmation' => ['required', 'string'],

            // Optional settings
            'currency' => ['nullable', 'string', 'max:10'],
            'timezone' => ['nullable', 'string', 'max:60'],
            'tax_rate' => ['nullable', 'numeric', 'min:0', 'max:100'],
            'tax_type' => ['nullable', 'string', Rule::in(['inclusive', 'exclusive'])],
        ];
    }

    public function messages(): array
    {
        return [
            'business_type.in' => 'Business type must be one of: ' . implode(', ', ModuleRegistry::validTypes()),
        ];
    }
}
