<?php

namespace HelpGent\Database\Migrations;

defined( 'ABSPATH' ) || exit;

use HelpGent\WpMVC\Contracts\Migration;

class AddEntryStarredToResponses implements Migration {
    public function more_than_version() {
        return '3.0.0-entries-starred';
    }

    public function execute(): bool {
        global $wpdb;

        $starred_column = $wpdb->get_results(
            $wpdb->prepare(
                "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = %s AND table_name = %s AND COLUMN_NAME = 'is_starred'",
                DB_NAME,
                "{$wpdb->prefix}helpgent_responses"
            )
        );

        if ( empty( $starred_column ) ) {
            $wpdb->query(
                "ALTER TABLE {$wpdb->prefix}helpgent_responses ADD COLUMN is_starred TINYINT NOT NULL DEFAULT 0 COMMENT 'value: 0/1' AFTER is_read"
            );
        }

        return true;
    }
}
