<?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\ORM\Schema;

use Cycle\Database\Schema\AbstractTable;

defined( 'ABSPATH' ) || exit;

/**
 * Customer table schema
 */
class CustomerSchema extends AbstractSchema
{
    public const TABLE_NAME = 'bflex_customers';

    public function define(): AbstractTable
    {
        $schema = $this->database->table(self::TABLE_NAME)->getSchema();

        $schema->column('id')->integer()->primary();
        $schema->column('first_name')->string(100);
        $schema->column('last_name')->string(100);
        $schema->column('email')->string(100);
        $schema->column('phone')->string(50)->nullable();
        $schema->column('metadata')->json()->nullable();
        $schema->column('wp_user_id')->bigInteger()->nullable();

        $this->addTimestamps($schema);

        // Indexes
        $schema->index(['email'])->unique();
        $schema->index(['wp_user_id']);

        return $schema;
    }
}
