<?php

namespace Modules\Patient\DTO;

use Illuminate\Http\Request;

class PatientSettingFilter
{
    public function __construct(
        public readonly ?string $search = null,
        public readonly string $status = 'Active',
        public readonly ?string $code = null,
        public readonly ?string $is_synced = '1' ?? '0',
        public readonly int $perPage = 15,
    ) {}

    public static function fromRequest(Request $request): self
    {
        return new self(
            search: $request->filled('search')
                ? trim($request->search)
                : null,

            status: $request->filled('status')
                ? $request->status
                : 'Active',

            code: $request->input('code'),

            is_synced: $request->input('is_synced') ?? '1',

            perPage: $request->filled('per_page')
                ? (int) $request->per_page
                : 15,
        );
    }
}
