<?php
// _Core/FollowupScheduler.php
// Auto-scheduling logic for next follow-up dates based on follow-up type.

class FollowupScheduler
{
    /**
     * Returns next follow-up date (Y-m-d) based on follow-up type.
     * Edit rules below as per business model.
     */
    public static function getNextDate($type)
    {
        $type = strtolower(trim($type));

        switch ($type) {
            case 'new lead':
            case 'first call':
                return date('Y-m-d', strtotime('+1 day'));

            case 'followup call':
            case 'call back':
                return date('Y-m-d', strtotime('+2 days'));

            case 'site visit':
                return date('Y-m-d', strtotime('+3 days'));

            case 'proposal shared':
            case 'proposal followup':
                return date('Y-m-d', strtotime('+5 days'));

            case 'negotiation':
                return date('Y-m-d', strtotime('+7 days'));

            case 'not interested':
            case 'closed':
                return null; // no further follow-up

            default:
                // fallback rule
                return date('Y-m-d', strtotime('+2 days'));
        }
    }

    /**
     * Determine automatic customer status update
     */
    public static function nextStatus($current, $followupType)
    {
        $current = strtolower($current);
        $f = strtolower($followupType);

        if ($current === 'new' && in_array($f, ['first call','new lead','followup call'])) {
            return 'Followup';
        }

        if (in_array($f, ['site visit'])) {
            return 'Followup';
        }

        if (in_array($f, ['proposal shared','proposal followup'])) {
            return 'Proposal';
        }

        if (in_array($f, ['negotiation'])) {
            return 'Proposal';
        }

        if (in_array($f, ['closed','won'])) {
            return 'Closed';
        }

        return ucfirst($current); // no change
    }
}
