<?php

namespace App\Dominios\Clientes\DTO;

use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;

class AtualizarClienteDTO
{
    public function __construct(
        public readonly string $nome,
        public readonly string $email,
        public readonly string $cpf,
        public readonly string $telefone
    ) {}

    public static function fromArray(array $data): self
    {
        $validator = Validator::make($data, [
            'nome' => 'required|string|min:3|max:255',
            'email' => 'required|email|max:255',
            'cpf' => 'required|string|size:14',
            'telefone' => 'required|string|min:14|max:15'
        ]);

        if ($validator->fails()) {
            throw new ValidationException($validator);
        }

        return new self(
            nome: $data['nome'],
            email: $data['email'],
            cpf: $data['cpf'],
            telefone: $data['telefone']
        );
    }

    public function toArray(): array
    {
        return [
            'nome' => $this->nome,
            'email' => $this->email,
            'cpf' => $this->cpf,
            'telefone' => $this->telefone
        ];
    }
} 