<?php
/**
 * BookiFlex Core
 *
 * @package    BookiFlex
 * @subpackage Core
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */

declare(strict_types=1);

namespace BookiFlex\Core\Model\Customer;

use BookiFlex\Core\Model\Identifiable;
use BookiFlex\Core\Model\Timestamps;
use BookiFlex\Core\Util\DateTimeUtils;

defined( 'ABSPATH' ) || exit;

class Customer
{
    use Timestamps;
    use Identifiable;

    private array $metadata = [];

    public function __construct(
        private string $firstName,
        private string $lastName,
        private string $email,
        private string $phone = ''
    ) {
        $this->createdAt = DateTimeUtils::nowUtc();
    }

    public function getFirstName(): string
    {
        return $this->firstName;
    }

    public function getLastName(): string
    {
        return $this->lastName;
    }

    public function getEmail(): string
    {
        return $this->email;
    }

    public function getPhone(): string
    {
        return $this->phone;
    }

    public function setFirstName(string $value): void
    {
        $this->firstName = $value;
    }

    public function setLastName(string $value): void
    {
        $this->lastName = $value;
    }

    public function setEmail(string $value): void
    {
        if (filter_var($value, FILTER_VALIDATE_EMAIL)) {
            $this->email = $value;
        }
    }

    public function setPhone(string $value): void
    {
        $this->phone = $value;
    }

    public function getMetadata(): array
    {
        return $this->metadata;
    }

    public function setMetadata(array $metadata): void
    {
        $this->metadata = $metadata;
    }

    public function getAddress(): string
    {
        return $this->metadata['address'] ?? '';
    }

    public function getCity(): string
    {
        return $this->metadata['city'] ?? '';
    }

    public function getCountry(): string
    {
        return $this->metadata['country'] ?? '';
    }

    public function getPostalCode(): string
    {
        return $this->metadata['postalCode'] ?? '';
    }

    public function getNotes(): string
    {
        return $this->metadata['notes'] ?? '';
    }
}
