<?php
/**
 * Accounts Seeder
 *
 * Seeds initial account data
 * Converted from Eloquent to BaseModel
 *
 * @package FleekDash
 * @subpackage Database
 */

namespace FleekDash\Database\Seeders;

use FleekDash\Models\Accounts as AccountsModel;

defined('ABSPATH') || exit;

/**
 * Class Accounts
 *
 * Represents the seeder for the 'accounts' table.
 *
 * @package FleekDash\Database\Seeders
 * @since 1.0.0
 */
class Accounts {

	/**
	 * Run the database seeds.
	 *
	 * @return void
	 */
	public static function run() {
		global $wpdb;

		// Insert data to the tables.
		$accounts = array(
			array(
				'user_id'    => '1',
				'host'       => 'localhost',
				'port'       => 3306,
				'first_name' => 'John',
				'last_name'  => 'Doe',
				'email'      => 'demouser1@email.com',
				'name'       => 'John Doe',
				'password'   => 'password',
				'created_at' => gmdate( 'Y-m-d H:i:s' ),
				'updated_at' => gmdate( 'Y-m-d H:i:s' ),
			),
			array(
				'user_id'    => '2',
				'host'       => 'localhost',
				'port'       => 3306,
				'first_name' => 'Jane',
				'last_name'  => 'Doe',
				'email'      => 'demouser2@email.com',
				'name'       => 'Jane Doe',
				'password'   => 'password',
				'created_at' => gmdate( 'Y-m-d H:i:s' ),
				'updated_at' => gmdate( 'Y-m-d H:i:s' ),
			),
		);

		foreach ( $accounts as $account ) {
			// Check if account already exists
			$exists = $wpdb->get_var($wpdb->prepare(
				"SELECT COUNT(*) FROM {$wpdb->prefix}accounts WHERE user_id = %s",
				$account['user_id']
			));

			if ( ! $exists ) {
				AccountsModel::create( $account );
			}
		}
	}
}
