package DBIx::Fast::Profile::Base;

use v5.38;
use Object::Pad 0.807;
use Carp qw(croak);
use Scalar::Util qw(weaken);
use DBIx::Fast::Output;

class DBIx::Fast::Profile::Base :does(DBIx::Fast::Output) {
    field $dbix       :param :reader;
    field $enabled    :param :accessor = 1;
    field $slow_query :param :accessor = 1.0;

    ADJUST {
        croak "Missing required parameter 'dbix'" unless defined $dbix;
        weaken($dbix);
    }

    # Envelope identity for DBIx::Fast::Output events.
    method _output_meta () {
        (my $driver = ref $self) =~ s/^.*:://;
        return { source => 'profile', driver => $driver };
    }

    method add_query        { }
    method init             { croak "Not implemented" }
    method get_slow_queries { croak "Not implemented" }
    method get_stats        { croak "Not implemented" }
    method print_stats      { croak "Not implemented" }

    # Driver-specific diagnostics. Default to no-ops (return undef) so a driver
    # with no native equivalent (e.g. SQLite) inherits them without re-stubbing
    # each one, and adding a new diagnostic to one driver does not make the
    # others croak. ::MariaDB overrides these with real implementations.
    method get_query_profile        { }
    method explain_query            { }
    method get_table_stats          { }
    method get_index_stats          { }
    method analyze_indexes          { }
    method print_index_analysis     { }
    method get_index_metrics        { }
    method monitor_connections      { }
    method get_current_connections  { }
    method get_processes            { }
    method print_connection_monitor { }
    method start_connection_monitor { }
}

1;

__END__

=head1 NAME

DBIx::Fast::Profile::Base - Abstract base class for database driver profiles

=head1 DESCRIPTION

Defines the interface that all driver-specific profile classes must implement.
Subclasses (e.g. L<DBIx::Fast::Profile::MariaDB>, L<DBIx::Fast::Profile::SQLite>)
override these methods to provide driver-native profiling and diagnostics.

=head1 METHODS

=head2 init

Initializes profiling for the specific database driver. Must be implemented by
subclasses.

=head2 add_query

Hook called when a query is executed. The base implementation is a no-op;
subclasses may override to record driver-level metrics.

=head2 get_slow_queries

Returns slow queries using driver-native facilities. Must be implemented by
subclasses.

=head2 get_stats

Returns driver-specific query and server statistics. Must be implemented by
subclasses.

=head2 print_stats

Prints a formatted report of driver-specific statistics. Must be implemented by
subclasses.

=head2 Driver diagnostics interface

The following methods form the driver diagnostics API. They default to no-ops
(return undef) here, so a driver with no native equivalent inherits them
unchanged, and are overridden by L<DBIx::Fast::Profile::MariaDB> with full
implementations. L<DBIx::Fast::Profile::SQLite> inherits the no-op defaults:

C<get_query_profile>, C<explain_query>, C<get_table_stats>,
C<get_index_stats>, C<analyze_indexes>, C<print_index_analysis>,
C<get_index_metrics>, C<monitor_connections>, C<get_current_connections>,
C<get_processes>, C<print_connection_monitor>, C<start_connection_monitor>.

=head1 AUTHOR

SeHarrys

=head1 LICENSE

This is free software under the Artistic License 2.0.

=cut
