<?php
/**
 * Per-day table splits for admin floor overview (8 → 8a, 8b, …).
 *
 * @package Maca_Menu_List
 */

if (!defined('ABSPATH')) {
    exit;
}

/**
 * Day-split records table name.
 *
 * @return string
 */
function maca_menulist_db_booking_table_day_splits_table() {
    global $wpdb;

    return $wpdb->prefix . 'maca_booking_table_day_splits';
}

/**
 * Ensure day-split table and booking.split_slot column exist.
 */
function maca_menulist_db_ensure_booking_day_split_schema() {
    global $wpdb;

    static $done = false;

    if ($done) {
        return;
    }

    $splits_table = maca_menulist_db_booking_table_day_splits_table();
    $bookings_table = maca_menulist_db_bookings_table();
    $charset_collate = $wpdb->get_charset_collate();

    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $splits_table)) !== $splits_table) {
        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange
        $wpdb->query(
            "CREATE TABLE $splits_table (
                id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                table_id bigint(20) unsigned NOT NULL,
                split_date date NOT NULL,
                split_slot_sizes varchar(64) DEFAULT NULL,
                created_at datetime DEFAULT CURRENT_TIMESTAMP,
                PRIMARY KEY (id),
                UNIQUE KEY table_date (table_id, split_date),
                KEY split_date (split_date)
            ) $charset_collate"
        );
    }

    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange
    if ($wpdb->get_var("SHOW COLUMNS FROM $splits_table LIKE 'split_slot_sizes'") !== 'split_slot_sizes') {
        $wpdb->query("ALTER TABLE $splits_table ADD COLUMN split_slot_sizes varchar(64) DEFAULT NULL AFTER split_date");
    }

    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $bookings_table)) === $bookings_table) {
        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange
        if (!$wpdb->get_var("SHOW COLUMNS FROM $bookings_table LIKE 'split_slot'")) {
            // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange
            $wpdb->query("ALTER TABLE $bookings_table ADD COLUMN split_slot varchar(2) DEFAULT NULL AFTER table_id");
        }
    }

    $done = true;
}

/**
 * Normalize split slot letter (a–z).
 *
 * @param string $slot Slot from request.
 * @return string
 */
function maca_menulist_normalize_split_slot($slot) {
    $slot = strtolower(sanitize_key($slot));

    if ($slot === '' || !preg_match('/^[a-z]$/', $slot)) {
        return '';
    }

    return $slot;
}

/**
 * Display number for a split part, e.g. 8 + a → 8a.
 *
 * @param string $base_number Base table number.
 * @param string $slot        Slot letter.
 * @return string
 */
function maca_menulist_format_split_table_number($base_number, $slot) {
    $base_number = trim((string) $base_number);
    $slot = maca_menulist_normalize_split_slot($slot);

    if ($base_number === '' || $slot === '') {
        return $base_number;
    }

    return $base_number . $slot;
}

/**
 * Day-split row for a table and date.
 *
 * @param int    $table_id Table ID.
 * @param string $date     Date Y-m-d.
 * @return object|null
 */
function maca_menulist_get_table_day_split_row($table_id, $date) {
    global $wpdb;

    $table_id = absint($table_id);
    $date = sanitize_text_field($date);

    if ($table_id <= 0 || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
        return null;
    }

    maca_menulist_db_ensure_booking_day_split_schema();

    $splits_table = maca_menulist_db_booking_table_day_splits_table();

    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    return $wpdb->get_row(
        $wpdb->prepare(
            "SELECT * FROM $splits_table WHERE table_id = %d AND split_date = %s LIMIT 1",
            $table_id,
            $date
        )
    );
}

/**
 * Whether a table is split for a given date in floor overview.
 *
 * @param int    $table_id Table ID.
 * @param string $date     Date Y-m-d.
 * @return bool
 */
function maca_menulist_is_table_split_for_date($table_id, $date) {
    global $wpdb;

    $table_id = absint($table_id);
    $date = sanitize_text_field($date);

    if ($table_id <= 0 || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
        return false;
    }

    maca_menulist_db_ensure_booking_day_split_schema();

    $splits_table = maca_menulist_db_booking_table_day_splits_table();

    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $found = $wpdb->get_var(
        $wpdb->prepare(
            "SELECT id FROM $splits_table WHERE table_id = %d AND split_date = %s LIMIT 1",
            $table_id,
            $date
        )
    );

    return !empty($found);
}

/**
 * Consecutive day-split parts (a, b, …) occupied by one booking.
 *
 * @param object      $booking Booking row.
 * @param object|null $table   Table row.
 * @param string      $date    Date Y-m-d.
 * @return array<int, string>
 */
function maca_menulist_booking_day_split_slots($booking, $table, $date) {
    if (!$booking || !$table || !maca_menulist_is_table_split_for_date((int) $table->id, $date)) {
        return array();
    }

    $start = isset($booking->split_slot) ? maca_menulist_normalize_split_slot((string) $booking->split_slot) : '';
    if ($start === '') {
        return array();
    }

    $letters = maca_menulist_get_table_split_slot_letters($table, $date);
    $capacities = maca_menulist_get_table_split_capacities($table, $date);
    $start_index = array_search($start, $letters, true);

    if ($start_index === false) {
        return array( $start );
    }

    $remaining = max(1, (int) $booking->party_size);
    $slots = array();

    for ($i = $start_index; $i < count($letters) && $remaining > 0; $i++) {
        $slots[] = $letters[ $i ];
        $remaining -= isset($capacities[ $i ]) ? (int) $capacities[ $i ] : 0;
    }

    return $slots;
}

/**
 * Whether a booking occupies a day-split part (including multi-part spans).
 *
 * @param object      $booking Booking row.
 * @param string      $slot    Slot letter.
 * @param object|null $table   Table row.
 * @param string      $date    Date Y-m-d.
 * @return bool
 */
function maca_menulist_booking_uses_day_split_slot($booking, $slot, $table, $date) {
    $slot = maca_menulist_normalize_split_slot($slot);

    return $slot !== '' && in_array($slot, maca_menulist_booking_day_split_slots($booking, $table, $date), true);
}

/**
 * Seats from one booking counted on a single day-split part.
 *
 * @param object      $booking Booking row.
 * @param string      $slot    Slot letter.
 * @param object|null $table   Table row.
 * @param string      $date    Date Y-m-d.
 * @return int
 */
function maca_menulist_booking_seats_on_day_split_slot($booking, $slot, $table, $date) {
    if (!maca_menulist_booking_uses_day_split_slot($booking, $slot, $table, $date)) {
        return 0;
    }

    $slot = maca_menulist_normalize_split_slot($slot);
    $letters = maca_menulist_get_table_split_slot_letters($table, $date);
    $capacities = maca_menulist_get_table_split_capacities($table, $date);
    $index = array_search($slot, $letters, true);

    if ($index === false || !isset($capacities[ $index ])) {
        return 0;
    }

    return (int) $capacities[ $index ];
}

/**
 * Find consecutive free day-split parts that fit a party.
 *
 * @param int              $party       Party size.
 * @param array<int, int>  $capacities  Seat cap per part.
 * @param array<int, bool> $slot_used   Parts already reserved.
 * @return array{0: int, 1: int}|null Start/end indexes inclusive.
 */
function maca_menulist_find_consecutive_day_split_range($party, array $capacities, array $slot_used) {
    $party = max(1, (int) $party);
    $count = count($capacities);

    for ($i = 0; $i < $count; $i++) {
        if (!empty($slot_used[ $i ])) {
            continue;
        }

        $consumed = 0;
        $end = $i;

        while ($end < $count) {
            if (!empty($slot_used[ $end ])) {
                continue 2;
            }

            $consumed += (int) ( $capacities[ $end ] ?? 0 );
            if ($consumed >= $party) {
                return array( $i, $end );
            }

            $end++;
        }
    }

    return null;
}

/**
 * Whether any blocking booking on a split day lacks a split assignment.
 *
 * @param int    $table_id Table ID.
 * @param string $date     Date Y-m-d.
 * @return bool
 */
function maca_menulist_day_split_needs_booking_assignment($table_id, $date) {
    $table_id = absint($table_id);
    $date = sanitize_text_field($date);

    if ($table_id <= 0 || !maca_menulist_is_table_split_for_date($table_id, $date)) {
        return false;
    }

    $blocking_statuses = maca_menulist_get_blocking_booking_statuses();

    foreach (maca_menulist_db_get_table_bookings_for_date($date, $table_id) as $booking) {
        if (!in_array((string) $booking->status, $blocking_statuses, true)) {
            continue;
        }

        $slot = isset($booking->split_slot) ? maca_menulist_normalize_split_slot((string) $booking->split_slot) : '';
        if ($slot === '') {
            return true;
        }
    }

    return false;
}

/**
 * Resolve seat capacities for a day split from layout key or string.
 *
 * @param object|null $table  Table row.
 * @param string      $layout default|table|4,2|2,2,2|…
 * @return array<int, int>|WP_Error
 */
function maca_menulist_resolve_day_split_capacities($table, $layout) {
    $layout = strtolower(trim(sanitize_text_field((string) $layout)));

    if ($layout === '' || $layout === 'default' || $layout === 'table') {
        return maca_menulist_get_table_split_capacities($table, '');
    }

    return maca_menulist_parse_split_slot_sizes_input($layout, (int) $table->seats);
}

/**
 * Preset layout choices for the floor overview (per selected date).
 *
 * @param object|null $table Table row.
 * @return array<int, array{value: string, label: string}>
 */
function maca_menulist_get_day_layout_presets($table) {
    if (!$table || !maca_menulist_table_is_splittable($table)) {
        return array();
    }

    $seats = max(1, (int) $table->seats);
    $presets = array(
        array(
            'value' => 'default',
            'label' => sprintf(
                /* translators: %s: layout from table settings */
                __('Bordets standard (%s)', 'maca-restu-pro'),
                maca_menulist_table_split_layout_label($table, '')
            ),
        ),
    );
    $seen = array();

    $add_preset = static function ($value, $label) use (&$presets, &$seen) {
        if (isset($seen[ $value ])) {
            return;
        }
        $seen[ $value ] = true;
        $presets[] = array(
            'value' => $value,
            'label' => $label,
        );
    };

    if ($seats === 6) {
        $add_preset('4,2', '4+2');
        $add_preset('2,2,2', '3×2');
    }

    for ($per = $seats; $per >= 1; $per--) {
        if ($seats % $per !== 0) {
            continue;
        }

        $parts = array_fill(0, (int) ($seats / $per), $per);
        $value = implode(',', $parts);
        $add_preset($value, maca_menulist_format_capacities_layout_label($parts));
    }

    return $presets;
}

/**
 * Split a splittable table for one date (floor overview).
 *
 * @param int    $table_id Table ID.
 * @param string $date     Date Y-m-d.
 * @param string $layout   Layout key or sizes, e.g. 4,2 or 2,2,2.
 * @return true|WP_Error
 */
function maca_menulist_split_table_for_date($table_id, $date, $layout = 'default') {
    global $wpdb;

    $table_id = absint($table_id);
    $date = sanitize_text_field($date);
    $table = maca_menulist_db_get_booking_table($table_id);

    if (!$table || !maca_menulist_table_is_splittable($table)) {
        return new WP_Error('not_splittable', __('Bordet är inte markerat som delningsbart.', 'maca-restu-pro'));
    }

    if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
        return new WP_Error('invalid_date', __('Ogiltigt datum.', 'maca-restu-pro'));
    }

    $capacities = maca_menulist_resolve_day_split_capacities($table, $layout);
    if (is_wp_error($capacities)) {
        return $capacities;
    }

    $encoded = maca_menulist_encode_split_slot_sizes($capacities);

    maca_menulist_db_ensure_booking_day_split_schema();

    $splits_table = maca_menulist_db_booking_table_day_splits_table();
    $existing = maca_menulist_get_table_day_split_row($table_id, $date);

    if ($existing) {
        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
        $updated = $wpdb->update(
            $splits_table,
            array('split_slot_sizes' => $encoded),
            array(
                'table_id' => $table_id,
                'split_date' => $date,
            ),
            array('%s'),
            array('%d', '%s')
        );

        if ($updated === false) {
            return new WP_Error('db_error', __('Kunde inte uppdatera delningen.', 'maca-restu-pro'));
        }
    } else {
        $inserted = $wpdb->insert(
            $splits_table,
            array(
                'table_id' => $table_id,
                'split_date' => $date,
                'split_slot_sizes' => $encoded,
                'created_at' => maca_menulist_wp_now_mysql(),
            ),
            array('%d', '%s', '%s', '%s')
        );

        if (!$inserted) {
            return new WP_Error('db_error', __('Kunde inte dela bordet.', 'maca-restu-pro'));
        }
    }

    maca_menulist_assign_bookings_to_split_slots_for_date($table_id, $date);

    return true;
}

/**
 * Merge split parts back to one table for a date.
 *
 * @param int    $table_id Table ID.
 * @param string $date     Date Y-m-d.
 * @return true|WP_Error
 */
function maca_menulist_unsplit_table_for_date($table_id, $date) {
    global $wpdb;

    $table_id = absint($table_id);
    $date = sanitize_text_field($date);

    if ($table_id <= 0 || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
        return new WP_Error('invalid', __('Ogiltigt bord eller datum.', 'maca-restu-pro'));
    }

    if (!maca_menulist_is_table_split_for_date($table_id, $date)) {
        return new WP_Error('not_split', __('Bordet är inte delat denna dag.', 'maca-restu-pro'));
    }

    maca_menulist_db_ensure_booking_day_split_schema();

    $splits_table = maca_menulist_db_booking_table_day_splits_table();
    $bookings_table = maca_menulist_db_bookings_table();

    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $wpdb->delete(
        $splits_table,
        array(
            'table_id' => $table_id,
            'split_date' => $date,
        ),
        array('%d', '%s')
    );

    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $wpdb->query(
        $wpdb->prepare(
            "UPDATE $bookings_table SET split_slot = NULL WHERE table_id = %d AND booking_date = %s",
            $table_id,
            $date
        )
    );

    return true;
}

/**
 * Assign existing bookings on a date to split slots a, b, c…
 *
 * @param int    $table_id Table ID.
 * @param string $date     Date Y-m-d.
 * @return void
 */
function maca_menulist_assign_bookings_to_split_slots_for_date($table_id, $date) {
    global $wpdb;

    $table = maca_menulist_db_get_booking_table($table_id);
    if (!$table) {
        return;
    }

    $letters = maca_menulist_get_table_split_slot_letters($table, $date);
    if (empty($letters)) {
        return;
    }

    $blocking_statuses = maca_menulist_get_blocking_booking_statuses();
    $bookings = array();

    foreach (maca_menulist_db_get_table_bookings_for_date($date, $table_id) as $booking) {
        if (!in_array($booking->status, $blocking_statuses, true)) {
            continue;
        }
        $bookings[] = $booking;
    }

    usort(
        $bookings,
        static function ($a, $b) {
            $time_cmp = strcmp((string) $a->booking_time, (string) $b->booking_time);
            if ($time_cmp !== 0) {
                return $time_cmp;
            }

            return (int) $a->id <=> (int) $b->id;
        }
    );

    $capacities = maca_menulist_get_table_split_capacities($table, $date);
    $bookings_table = maca_menulist_db_bookings_table();
    $slot_used = array_fill(0, count($letters), false);

    foreach ($bookings as $booking) {
        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
        $wpdb->update(
            $bookings_table,
            array('split_slot' => null),
            array('id' => (int) $booking->id),
            array('%s'),
            array('%d')
        );
    }

    foreach ($bookings as $booking) {
        $party = max(1, (int) $booking->party_size);
        $range = maca_menulist_find_consecutive_day_split_range($party, $capacities, $slot_used);

        if ($range === null) {
            continue;
        }

        list($start, $end) = $range;

        for ($k = $start; $k <= $end; $k++) {
            $slot_used[ $k ] = true;
        }

        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
        $wpdb->update(
            $bookings_table,
            array('split_slot' => $letters[ $start ]),
            array('id' => (int) $booking->id),
            array('%s'),
            array('%d')
        );
    }
}

/**
 * Build one floor-overview table row (physical or split part).
 *
 * @param object $table      Table row.
 * @param string $date       Date Y-m-d.
 * @param string $time_norm  Time HH:MM.
 * @param string $split_slot Slot letter or empty for whole table.
 * @return array<string, mixed>
 */
function maca_menulist_build_admin_floor_table_row($table, $date, $time_norm, $split_slot = '') {
    $table_id = (int) $table->id;
    $split_slot = maca_menulist_normalize_split_slot($split_slot);
    $is_split_part = ($split_slot !== '');
    $is_splittable = maca_menulist_table_is_splittable($table);
    $split_party_size = maca_menulist_table_split_party_size($table);
    $max_bookings = maca_menulist_table_max_share_bookings($table, $date);
    $split_for_date = maca_menulist_is_table_split_for_date($table_id, $date);
    $base_number = (string) $table->table_number;

    $capacities = maca_menulist_get_table_split_capacities($table, $date);
    $split_layout = maca_menulist_format_capacities_layout_label($capacities);
    if ($split_layout === '') {
        $split_layout = maca_menulist_table_split_layout_label($table, '');
    }
    $letters = maca_menulist_get_table_split_slot_letters($table, $date);
    $slot_index = array_search($split_slot, $letters, true);

    if ($is_split_part) {
        $seats = ($slot_index !== false && isset($capacities[ $slot_index ]))
            ? (int) $capacities[ $slot_index ]
            : $split_party_size;
        $display_number = maca_menulist_format_split_table_number($base_number, $split_slot);
        $bookings_at_time = maca_menulist_get_table_bookings_at_time($table_id, $date, $time_norm, $split_slot);
    } else {
        $seats = (int) $table->seats;
        $display_number = $base_number;
        $bookings_at_time = maca_menulist_get_table_bookings_at_time($table_id, $date, $time_norm);
    }

    $booking_count = count($bookings_at_time);
    $occupied_seats = 0;

    foreach ($bookings_at_time as $blocking_row) {
        if ($is_split_part && $split_for_date) {
            $occupied_seats += maca_menulist_booking_seats_on_day_split_slot($blocking_row, $split_slot, $table, $date);
        } else {
            $occupied_seats += max(1, (int) $blocking_row->party_size);
        }
    }

    $occupied_seats = min($seats, $occupied_seats);
    $remaining_seats = max(0, $seats - $occupied_seats);
    $is_empty = ($booking_count === 0);

    if ($is_split_part) {
        $can_share = false;
        $is_full = !$is_empty;
    } else {
        $can_share = !$is_empty
            && $booking_count < $max_bookings
            && $remaining_seats > 0
            && !$split_for_date;
        $is_full = !$is_empty && !$can_share;
    }

    if ($is_split_part) {
        $seat_slots = maca_menulist_build_floor_seat_slots_from_capacities(array( $seats ), $bookings_at_time);
    } elseif ($is_splittable && $split_for_date) {
        $seat_slots = maca_menulist_build_floor_seat_slots_from_capacities($capacities, $bookings_at_time);
    } elseif ($is_splittable) {
        $seat_slots = maca_menulist_build_floor_seat_slots_from_capacities(array( (int) $table->seats ), $bookings_at_time);
    } else {
        $seat_slots = maca_menulist_build_floor_seat_slots($seats, 0, $bookings_at_time);
    }

    $booking_payloads = array();

    foreach ($bookings_at_time as $blocking) {
        if (!in_array((string) $blocking->status, maca_menulist_get_blocking_booking_statuses(), true)) {
            continue;
        }

        if ($is_split_part && $split_for_date) {
            $anchor = isset($blocking->split_slot) ? maca_menulist_normalize_split_slot((string) $blocking->split_slot) : '';
            if ($anchor !== $split_slot) {
                continue;
            }
        }

        $booking_payloads[] = maca_menulist_build_floor_booking_payload($blocking, $time_norm);
    }

    return array(
        'id' => $table_id,
        'split_slot' => $split_slot,
        'table_number' => $display_number,
        'base_table_number' => $base_number,
        'seats' => $seats,
        'is_splittable' => $is_splittable,
        'split_party_size' => $split_party_size,
        'split_capacities' => $capacities,
        'split_layout' => $split_layout,
        'split_for_date' => $split_for_date,
        'is_split_part' => $is_split_part,
        'can_split_day' => $is_splittable && !$split_for_date && !$is_split_part,
        'can_manage_day_split' => $is_splittable && ( !$is_split_part || ( $split_for_date && $split_slot === 'a' ) ),
        'day_layout_presets' => ( $is_splittable && ! $is_split_part ) || ( $split_for_date && $split_slot === 'a' )
            ? maca_menulist_get_day_layout_presets($table)
            : array(),
        'day_split_layout' => $split_for_date ? $split_layout : '',
        'day_split_layout_value' => $split_for_date ? implode(',', $capacities) : '',
        'can_unsplit_day' => $split_for_date && $is_split_part && $split_slot === 'a',
        'available' => $is_empty,
        'is_empty' => $is_empty,
        'is_partial' => $can_share,
        'is_full' => $is_full,
        'occupied_seats' => $occupied_seats,
        'seat_slots' => $seat_slots,
        'remaining_seats' => $remaining_seats,
        'booking_count' => $booking_count,
        'max_bookings' => $is_split_part ? 1 : $max_bookings,
        'bookings' => $booking_payloads,
        'booking' => $booking_payloads[0] ?? null,
    );
}

/**
 * Table label for admin lists (8a when split for that day).
 *
 * @param object|null $booking Booking row with table_number, split_slot, table_id, booking_date.
 * @return string
 */
function maca_menulist_get_booking_display_table_number($booking) {
    if (!$booking || empty($booking->table_number)) {
        return '';
    }

    $slot = isset($booking->split_slot) ? maca_menulist_normalize_split_slot((string) $booking->split_slot) : '';
    $table_id = isset($booking->table_id) ? (int) $booking->table_id : 0;
    $date = isset($booking->booking_date) ? (string) $booking->booking_date : '';

    if ($slot !== '' && $table_id > 0 && maca_menulist_is_table_split_for_date($table_id, $date)) {
        return maca_menulist_format_split_table_number((string) $booking->table_number, $slot);
    }

    return (string) $booking->table_number;
}

/**
 * Summary bucket for a floor row.
 *
 * @param array<string, mixed> $row Floor row.
 * @return string available|partial|full
 */
function maca_menulist_floor_row_summary_bucket($row) {
    if (!empty($row['is_empty'])) {
        return 'available';
    }
    if (!empty($row['is_partial'])) {
        return 'partial';
    }

    return 'full';
}
